public class OptionSpecBuilder extends AbstractOptionSpec<Void>
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
Modifier and Type | Method and Description |
---|---|
boolean |
acceptsArguments()
Does this option accept arguments?
|
Optional<ValueConverter<?>> |
argumentConverter()
Gives an object that can convert raw string values into objects of the
type of this option's argument
|
String |
argumentDescription()
Gives a short description of the option's argument.
|
String |
argumentTypeIndicator()
Gives an indication of the expected type of the option's
argument.
|
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.
|
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.
|
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.
|
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.
|
List<Void> |
defaultValues()
What values will the option take if none are specified on the command line?
|
boolean |
isRequired()
Is this option required on a command line?
|
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.
|
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.
|
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.
|
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.
|
boolean |
requiresArgument()
Does this option require an argument?
|
ArgumentAcceptingOptionSpec<String> |
withOptionalArg()
Informs an option parser that this builder's option accepts an optional argument.
|
ArgumentAcceptingOptionSpec<String> |
withRequiredArg()
Informs an option parser that this builder's option requires an argument.
|
description, equals, forHelp, hashCode, isForHelp, options, representsNonOptions, toString, value, valueOptional, values
public ArgumentAcceptingOptionSpec<String> withRequiredArg()
public ArgumentAcceptingOptionSpec<String> withOptionalArg()
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.
dependent
- an option whose presence on a command line makes this builder's option requiredotherDependents
- other options whose presence on a command line makes this builder's option requiredOptionException
- if any of the dependent options haven't been configured in the parser yetpublic 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.
dependent
- the option whose presence on a command line makes this builder's option requiredotherDependents
- other options whose presence on a command line makes this builder's option requiredpublic 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.
dependent
- an option whose absence on a command line makes this builder's option requiredotherDependents
- other options whose absence on a command line makes this builder's option requiredOptionException
- if any of the dependent options haven't been configured in the parser yetpublic 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.
dependent
- the option whose absence on a command line makes this builder's option requiredotherDependents
- other options whose absence on a command line makes this builder's option requiredpublic 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.
dependent
- an option whose presence on a command line makes this builder's option allowedotherDependents
- other options whose presence on a command line makes this builder's option allowedOptionException
- if any of the dependent options haven't been configured in the parser yetpublic 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.
dependent
- the option whose presence on a command line makes this builder's option allowedotherDependents
- other options whose presence on a command line makes this builder's option allowedpublic 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.
dependent
- an option whose absence on a command line makes this builder's option allowedotherDependents
- other options whose absence on a command line makes this builder's option allowedOptionException
- if any of the dependent options haven't been configured in the parser yetpublic 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.
dependent
- the option whose absence on a command line makes this builder's option allowedotherDependents
- other options whose absence on a command line makes this builder's option allowedpublic boolean acceptsArguments()
OptionDescriptor
public boolean requiresArgument()
OptionDescriptor
public boolean isRequired()
OptionDescriptor
public String argumentDescription()
OptionDescriptor
public String argumentTypeIndicator()
OptionDescriptor
public Optional<ValueConverter<?>> argumentConverter()
OptionDescriptor
public List<Void> defaultValues()
OptionDescriptor
© Copyright 2004-2016 Paul R. Holser, Jr. All rights reserved. Licensed under The MIT License.