public class SimpleCommandLinePropertySource extends CommandLinePropertySource<org.springframework.core.env.CommandLineArgs>
CommandLinePropertySource
implementation backed by a simple String array.
CommandLinePropertySource
implementation aims to provide the simplest
possible approach to parsing command line arguments. As with all CommandLinePropertySource
implementations, command line arguments are broken into two
distinct groups: option arguments and non-option arguments, as
described below (some sections copied from Javadoc for SimpleCommandLineArgsParser
):
--optName[=optValue]That is, options must be prefixed with "
--
", and may or may not specify a value.
If a value is specified, the name and value must be separated without spaces
by an equals sign ("=").
--foo --foo=bar --foo="bar then baz" --foo=bar,baz,biz
-foo --foo bar --foo = bar --foo=bar --foo=baz --foo=biz
--
" option
prefix will be considered as "non-option arguments" and made available through the
getNonOptionArgs()
method.
public static void main(String[] args) { PropertySource> ps = new SimpleCommandLinePropertySource(args); // ... }See
CommandLinePropertySource
for complete general usage examples.
When more fully-featured command line parsing is necessary, consider using
the provided JOptCommandLinePropertySource
, or implement your own
CommandLinePropertySource
against the command line parsing library of your
choice!
CommandLinePropertySource
,
JOptCommandLinePropertySource
PropertySource.StubPropertySource
COMMAND_LINE_PROPERTY_SOURCE_NAME, DEFAULT_NON_OPTION_ARGS_PROPERTY_NAME
logger, name, source
Constructor and Description |
---|
SimpleCommandLinePropertySource(String... args)
Create a new
SimpleCommandLinePropertySource having the default name
and backed by the given String[] of command line arguments. |
SimpleCommandLinePropertySource(String name,
String[] args)
Create a new
SimpleCommandLinePropertySource having the given name
and backed by the given String[] of command line arguments. |
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.
|
protected List<String> |
getOptionValues(String name)
Return the collection of values associated with the command line option having the
given name.
|
String[] |
getPropertyNames()
Get the property names for the option arguments.
|
containsProperty, getProperty, setNonOptionArgsPropertyName
public SimpleCommandLinePropertySource(String... args)
SimpleCommandLinePropertySource
having the default name
and backed by the given String[]
of command line arguments.public String[] getPropertyNames()
getPropertyNames
in class EnumerablePropertySource<org.springframework.core.env.CommandLineArgs>
protected boolean containsOption(String name)
CommandLinePropertySource
containsOption
in class CommandLinePropertySource<org.springframework.core.env.CommandLineArgs>
protected List<String> getOptionValues(String name)
CommandLinePropertySource
[]
)["bar"]
)["bar", "baz"]
)null
getOptionValues
in class CommandLinePropertySource<org.springframework.core.env.CommandLineArgs>
protected List<String> getNonOptionArgs()
CommandLinePropertySource
null
.getNonOptionArgs
in class CommandLinePropertySource<org.springframework.core.env.CommandLineArgs>