Class SimpleCommandLinePropertySource

  • public class SimpleCommandLinePropertySource
    extends CommandLinePropertySource<org.springframework.core.env.CommandLineArgs>
    CommandLinePropertySource implementation backed by a simple String array.


    This 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):

    Working with option arguments

    Option arguments must adhere to the exact syntax:
    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 ("=").

    Valid examples of option arguments

     --foo="bar then baz"

    Invalid examples of option arguments

     --foo bar
     --foo = bar
     --foo=bar --foo=baz --foo=biz

    Working with non-option arguments

    Any and all arguments specified at the command line without the " --" option prefix will be considered as "non-option arguments" and made available through the getNonOptionArgs() method.

    Typical usage

     public static void main(String[] args) {
           ps = new SimpleCommandLinePropertySource(args);
         // ...
    See CommandLinePropertySource for complete general usage examples.

    Beyond the basics

    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!

    Chris Beams
    See Also:
    CommandLinePropertySource, JOptCommandLinePropertySource
    • Method Detail

      • getOptionValues

        protected List<String> getOptionValues(String name)
        Description copied from class: CommandLinePropertySource
        Return the collection of values associated with the command line option having the given name.
        • if the option is present and has no argument (e.g.: "--foo"), return an empty collection ([])
        • if the option is present and has a single value (e.g. "--foo=bar"), return a collection having one element (["bar"])
        • if the option is present and the underlying command line parsing library supports multiple arguments (e.g. "--foo=bar --foo=baz"), return a collection having elements for each value (["bar", "baz"])
        • if the option is not present, return null
        Specified by:
        getOptionValues in class  CommandLinePropertySource<org.springframework.core.env.CommandLineArgs>