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,
JOptCommandLinePropertySourcePropertySource.StubPropertySourceCOMMAND_LINE_PROPERTY_SOURCE_NAME, DEFAULT_NON_OPTION_ARGS_PROPERTY_NAMElogger, name, source| Constructor and Description |
|---|
SimpleCommandLinePropertySource(java.lang.String... args)
Create a new
SimpleCommandLinePropertySource having the default name
and backed by the given String[] of command line arguments. |
SimpleCommandLinePropertySource(java.lang.String name,
java.lang.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(java.lang.String name)
Return whether the set of option arguments parsed from the command line contains
an option with the given name.
|
protected java.util.List<java.lang.String> |
getNonOptionArgs()
Return the collection of non-option arguments parsed from the command line.
|
protected java.util.List<java.lang.String> |
getOptionValues(java.lang.String name)
Return the collection of values associated with the command line option having the
given name.
|
java.lang.String[] |
getPropertyNames()
Get the property names for the option arguments.
|
containsProperty, getProperty, setNonOptionArgsPropertyNamepublic SimpleCommandLinePropertySource(java.lang.String... args)
SimpleCommandLinePropertySource having the default name
and backed by the given String[] of command line arguments.public SimpleCommandLinePropertySource(java.lang.String name,
java.lang.String[] args)
SimpleCommandLinePropertySource having the given name
and backed by the given String[] of command line arguments.public java.lang.String[] getPropertyNames()
getPropertyNames in class EnumerablePropertySource<org.springframework.core.env.CommandLineArgs>protected boolean containsOption(java.lang.String name)
CommandLinePropertySourcecontainsOption in class CommandLinePropertySource<org.springframework.core.env.CommandLineArgs>protected java.util.List<java.lang.String> getOptionValues(java.lang.String name)
CommandLinePropertySource[])["bar"])["bar", "baz"])nullgetOptionValues in class CommandLinePropertySource<org.springframework.core.env.CommandLineArgs>protected java.util.List<java.lang.String> getNonOptionArgs()
CommandLinePropertySourcenull.getNonOptionArgs in class CommandLinePropertySource<org.springframework.core.env.CommandLineArgs>