Top Description Fields Constructors Methods
joptsimple

public Class OptionSpecBuilder

extends NoArgumentOptionSpec
Class Inheritance
Imports
java.util.ArrayList, .Collections, .List

Allows callers to specify whether a given option accepts arguments (required or optional).

Instances are returned from OptionParser#accepts(String) to allow the formation of parser directives as sentences in a "fluent interface" language. For example:


  OptionParser parser = new OptionParser();
  parser.accepts( "c" ).withRequiredArg().ofType( Integer.class );

If no methods are invoked on an instance of this class, then that instance's option will accept no argument.

Note that you should not use the fluent interface clauses in a way that would defeat the typing of option arguments:


  OptionParser parser = new OptionParser();
  ArgumentAcceptingOptionSpec<String> optionC =
      parser.accepts( "c" ).withRequiredArg();
  optionC.ofType( Integer.class );  // DON'T THROW AWAY THE TYPE!

  String value = parser.parse( "-c", "2" ).valueOf( optionC );  // ClassCastException
Author
Paul Holser

Field Summary

Modifier and TypeField and Description
private final OptionParser

Constructor Summary

AccessConstructor and Description
pack-priv
OptionSpecBuilder(OptionParser parser, List<String> options, String description)

Method Summary

Modifier and TypeMethod and Description
private void
public OptionSpecBuilder

Returns:

self, so that the caller can add clauses to the fluent interface sentence
availableIf
(String
an option whose presence on a command line makes this builder's option allowed
dependent
,
String...
other options whose presence on a command line makes this builder's option allowed
otherDependents
)

Informs an option parser that this builder's option is allowed if the given option is present on the command line.

public OptionSpecBuilder

Returns:

self, so that the caller can add clauses to the fluent interface sentence
availableIf
(OptionSpec<?>
the option whose presence on a command line makes this builder's option allowed
dependent
,
OptionSpec<?>...
other options whose presence on a command line makes this builder's option allowed
otherDependents
)

Informs an option parser that this builder's option is allowed if the given option is present on the command line.

public OptionSpecBuilder

Returns:

self, so that the caller can add clauses to the fluent interface sentence
availableUnless
(String
an option whose absence on a command line makes this builder's option allowed
dependent
,
String...
other options whose absence on a command line makes this builder's option allowed
otherDependents
)

Informs an option parser that this builder's option is allowed if the given option is absent on the command line.

public OptionSpecBuilder

Returns:

self, so that the caller can add clauses to the fluent interface sentence
availableUnless
(OptionSpec<?>
the option whose absence on a command line makes this builder's option allowed
dependent
,
OptionSpec<?>...
other options whose absence on a command line makes this builder's option allowed
otherDependents
)

Informs an option parser that this builder's option is allowed if the given option is absent on the command line.

public OptionSpecBuilder

Returns:

self, so that the caller can add clauses to the fluent interface sentence
requiredIf
(String
an option whose presence on a command line makes this builder's option required
dependent
,
String...
other options whose presence on a command line makes this builder's option required
otherDependents
)

Informs an option parser that this builder's option is required if the given option is present on the command line.

public OptionSpecBuilder

Returns:

self, so that the caller can add clauses to the fluent interface sentence
requiredIf
(OptionSpec<?>
the option whose presence on a command line makes this builder's option required
dependent
,
OptionSpec<?>...
other options whose presence on a command line makes this builder's option required
otherDependents
)

Informs an option parser that this builder's option is required if the given option is present on the command line.

public OptionSpecBuilder

Returns:

self, so that the caller can add clauses to the fluent interface sentence
requiredUnless
(String
an option whose absence on a command line makes this builder's option required
dependent
,
String...
other options whose absence on a command line makes this builder's option required
otherDependents
)

Informs an option parser that this builder's option is required if the given option is absent on the command line.

public OptionSpecBuilder

Returns:

self, so that the caller can add clauses to the fluent interface sentence
requiredUnless
(OptionSpec<?>
the option whose absence on a command line makes this builder's option required
dependent
,
OptionSpec<?>...
other options whose absence on a command line makes this builder's option required
otherDependents
)

Informs an option parser that this builder's option is required if the given option is absent on the command line.

private List<String>
validatedDependents(String dependent, String... otherDependents)

public ArgumentAcceptingOptionSpec<String>

Returns:

a specification for the option
withOptionalArg
()

Informs an option parser that this builder's option accepts an optional argument.

public ArgumentAcceptingOptionSpec<String>

Returns:

a specification for the option
withRequiredArg
()

Informs an option parser that this builder's option requires an argument.

Inherited from joptsimple.NoArgumentOptionSpec:
acceptsArgumentsargumentDescriptionargumentTypeIndicatorconvertdefaultValueshandleOptionisRequiredrequiresArgument

Field Detail

parserback to summary
private final OptionParser parser

Constructor Detail

OptionSpecBuilderback to summary
pack-priv OptionSpecBuilder(OptionParser parser, List<String> options, String description)

Method Detail

attachToParserback to summary
private void attachToParser()
availableIfback to summary
public OptionSpecBuilder availableIf(String dependent, String... otherDependents)

Informs an option parser that this builder's option is allowed if the given option is present on the command line.

For a given option, you should not mix this with availableUnless to avoid conflicts.

Parameters
dependent:String

an option whose presence on a command line makes this builder's option allowed

otherDependents:String[]

other options whose presence on a command line makes this builder's option allowed

Returns:OptionSpecBuilder

self, so that the caller can add clauses to the fluent interface sentence

Exceptions
OptionException:
if any of the dependent options haven't been configured in the parser yet
availableIfback to summary
public OptionSpecBuilder availableIf(OptionSpec<?> dependent, OptionSpec<?>... otherDependents)

Informs an option parser that this builder's option is allowed if the given option is present on the command line.

For a given option, you should not mix this with requiredUnless to avoid conflicts.

This method recognizes only instances of options returned from the fluent interface methods.

Parameters
dependent:OptionSpec<?>

the option whose presence on a command line makes this builder's option allowed

otherDependents:OptionSpec<?>[]

other options whose presence on a command line makes this builder's option allowed

Returns:OptionSpecBuilder

self, so that the caller can add clauses to the fluent interface sentence

availableUnlessback to summary
public OptionSpecBuilder availableUnless(String dependent, String... otherDependents)

Informs an option parser that this builder's option is allowed if the given option is absent on the command line.

For a given option, you should not mix this with requiredIf to avoid conflicts.

Parameters
dependent:String

an option whose absence on a command line makes this builder's option allowed

otherDependents:String[]

other options whose absence on a command line makes this builder's option allowed

Returns:OptionSpecBuilder

self, so that the caller can add clauses to the fluent interface sentence

Exceptions
OptionException:
if any of the dependent options haven't been configured in the parser yet
availableUnlessback to summary
public OptionSpecBuilder availableUnless(OptionSpec<?> dependent, OptionSpec<?>... otherDependents)

Informs an option parser that this builder's option is allowed if the given option is absent on the command line.

For a given option, you should not mix this with requiredIf to avoid conflicts.

This method recognizes only instances of options returned from the fluent interface methods.

Parameters
dependent:OptionSpec<?>

the option whose absence on a command line makes this builder's option allowed

otherDependents:OptionSpec<?>[]

other options whose absence on a command line makes this builder's option allowed

Returns:OptionSpecBuilder

self, so that the caller can add clauses to the fluent interface sentence

requiredIfback to summary
public OptionSpecBuilder requiredIf(String dependent, String... otherDependents)

Informs an option parser that this builder's option is required if the given option is present on the command line.

For a given option, you should not mix this with requiredUnless to avoid conflicts.

Parameters
dependent:String

an option whose presence on a command line makes this builder's option required

otherDependents:String[]

other options whose presence on a command line makes this builder's option required

Returns:OptionSpecBuilder

self, so that the caller can add clauses to the fluent interface sentence

Exceptions
OptionException:
if any of the dependent options haven't been configured in the parser yet
requiredIfback to summary
public OptionSpecBuilder requiredIf(OptionSpec<?> dependent, OptionSpec<?>... otherDependents)

Informs an option parser that this builder's option is required if the given option is present on the command line.

For a given option, you should not mix this with requiredUnless to avoid conflicts.

This method recognizes only instances of options returned from the fluent interface methods.

Parameters
dependent:OptionSpec<?>

the option whose presence on a command line makes this builder's option required

otherDependents:OptionSpec<?>[]

other options whose presence on a command line makes this builder's option required

Returns:OptionSpecBuilder

self, so that the caller can add clauses to the fluent interface sentence

requiredUnlessback to summary
public OptionSpecBuilder requiredUnless(String dependent, String... otherDependents)

Informs an option parser that this builder's option is required if the given option is absent on the command line.

For a given option, you should not mix this with requiredIf to avoid conflicts.

Parameters
dependent:String

an option whose absence on a command line makes this builder's option required

otherDependents:String[]

other options whose absence on a command line makes this builder's option required

Returns:OptionSpecBuilder

self, so that the caller can add clauses to the fluent interface sentence

Exceptions
OptionException:
if any of the dependent options haven't been configured in the parser yet
requiredUnlessback to summary
public OptionSpecBuilder requiredUnless(OptionSpec<?> dependent, OptionSpec<?>... otherDependents)

Informs an option parser that this builder's option is required if the given option is absent on the command line.

For a given option, you should not mix this with requiredIf to avoid conflicts.

This method recognizes only instances of options returned from the fluent interface methods.

Parameters
dependent:OptionSpec<?>

the option whose absence on a command line makes this builder's option required

otherDependents:OptionSpec<?>[]

other options whose absence on a command line makes this builder's option required

Returns:OptionSpecBuilder

self, so that the caller can add clauses to the fluent interface sentence

validatedDependentsback to summary
private List<String> validatedDependents(String dependent, String... otherDependents)
withOptionalArgback to summary
public ArgumentAcceptingOptionSpec<String> withOptionalArg()

Informs an option parser that this builder's option accepts an optional argument.

Returns:ArgumentAcceptingOptionSpec<String>

a specification for the option

withRequiredArgback to summary
public ArgumentAcceptingOptionSpec<String> withRequiredArg()

Informs an option parser that this builder's option requires an argument.

Returns:ArgumentAcceptingOptionSpec<String>

a specification for the option