| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
package joptsimple; |
| 7 | |
|
| 8 | |
import java.util.List; |
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
class OptionalArgumentOptionSpec extends ArgumentAcceptingOptionSpec { |
| 18 | |
OptionalArgumentOptionSpec( String option ) { |
| 19 | 98 | super( option, false ); |
| 20 | 98 | } |
| 21 | |
|
| 22 | |
OptionalArgumentOptionSpec( List options, String description ) { |
| 23 | 142 | super( options, false, description ); |
| 24 | 142 | } |
| 25 | |
|
| 26 | |
protected void detectOptionArgument( OptionParser parser, ArgumentList arguments, |
| 27 | |
OptionSet detectedOptions ) { |
| 28 | |
|
| 29 | 88 | if ( arguments.hasMore() ) { |
| 30 | 76 | String nextArgument = arguments.peek(); |
| 31 | |
|
| 32 | 76 | if ( !parser.looksLikeAnOption( nextArgument ) ) |
| 33 | 52 | handleOptionArgument( parser, detectedOptions, arguments ); |
| 34 | 24 | else if ( isArgumentOfNumberType() && canConvertArgument( nextArgument ) ) |
| 35 | 8 | addArguments( detectedOptions, arguments.next() ); |
| 36 | |
else |
| 37 | 16 | detectedOptions.addAll( options() ); |
| 38 | 76 | } |
| 39 | |
else |
| 40 | 12 | detectedOptions.addAll( options() ); |
| 41 | 88 | } |
| 42 | |
|
| 43 | |
private void handleOptionArgument( OptionParser parser, OptionSet detectedOptions, |
| 44 | |
ArgumentList arguments ) { |
| 45 | |
|
| 46 | 52 | if ( parser.posixlyCorrect() ) { |
| 47 | 6 | detectedOptions.addAll( options() ); |
| 48 | 6 | parser.noMoreOptions(); |
| 49 | |
} |
| 50 | |
else |
| 51 | 46 | addArguments( detectedOptions, arguments.next() ); |
| 52 | 52 | } |
| 53 | |
|
| 54 | |
void accept( OptionSpecVisitor visitor ) { |
| 55 | 10 | visitor.visit( this ); |
| 56 | 10 | } |
| 57 | |
} |