public class JOptCommandLinePropertySource extends CommandLinePropertySource<joptsimple.OptionSet>
CommandLinePropertySource
implementation backed by a JOpt OptionSet
.
OptionParser
against the String[]
of arguments
supplied to the main
method, and create a JOptCommandLinePropertySource
using the resulting OptionSet
object:
public static void main(String[] args) { OptionParser parser = new OptionParser(); parser.accepts("option1"); parser.accepts("option2").withRequiredArg(); OptionSet options = parser.parse(args); PropertySource> ps = new JOptCommandLinePropertySource(options); // ... }See
CommandLinePropertySource
for complete general usage examples.
Requires JOpt Simple version 4.3 or higher. Tested against JOpt up until 5.0.
CommandLinePropertySource
,
OptionParser
,
OptionSet
PropertySource.StubPropertySource
COMMAND_LINE_PROPERTY_SOURCE_NAME, DEFAULT_NON_OPTION_ARGS_PROPERTY_NAME
logger, name, source
Constructor and Description |
---|
JOptCommandLinePropertySource(joptsimple.OptionSet options)
Create a new
JOptCommandLinePropertySource having the default name
and backed by the given OptionSet . |
JOptCommandLinePropertySource(String name,
joptsimple.OptionSet options)
Create a new
JOptCommandLinePropertySource having the given name
and backed by the given OptionSet . |
Modifier and Type | Method and Description |
---|---|
protected boolean |
containsOption(String name)
Return whether the set of option arguments parsed from the command line contains
an option with the given name.
|
protected List<String> |
getNonOptionArgs()
Return the collection of non-option arguments parsed from the command line.
|
List<String> |
getOptionValues(String name)
Return the collection of values associated with the command line option having the
given name.
|
String[] |
getPropertyNames()
Return the names of all properties contained by the
source object (never
null ). |
containsProperty, getProperty, setNonOptionArgsPropertyName
public JOptCommandLinePropertySource(joptsimple.OptionSet options)
JOptCommandLinePropertySource
having the default name
and backed by the given OptionSet
.public JOptCommandLinePropertySource(String name, joptsimple.OptionSet options)
JOptCommandLinePropertySource
having the given name
and backed by the given OptionSet
.protected boolean containsOption(String name)
CommandLinePropertySource
containsOption
in class CommandLinePropertySource<joptsimple.OptionSet>
public String[] getPropertyNames()
EnumerablePropertySource
null
).getPropertyNames
in class EnumerablePropertySource<joptsimple.OptionSet>
@Nullable public List<String> getOptionValues(String name)
CommandLinePropertySource
[]
)["bar"]
)["bar", "baz"]
)null
getOptionValues
in class CommandLinePropertySource<joptsimple.OptionSet>
protected List<String> getNonOptionArgs()
CommandLinePropertySource
null
.getNonOptionArgs
in class CommandLinePropertySource<joptsimple.OptionSet>