public class SimpleCommandLinePropertySource extends CommandLinePropertySource<org.springframework.core.env.CommandLineArgs>
CommandLinePropertySource
実装。 この CommandLinePropertySource
実装は、コマンドライン引数を解析するための最も単純なアプローチを提供することを目的としています。すべての CommandLinePropertySource
実装と同様に、コマンドライン引数は、以下に説明するように、オプション引数と非 オプション引数の 2 つの異なるグループに分けられます(SimpleCommandLineArgsParser
の Javadoc からコピーされたセクションもあります)。
オプション引数は正確な構文に従う必要があります。
--optName[=optValue]
つまり、オプションの先頭に "--
" を付ける必要があり、値を指定する場合としない場合があります。値を指定する場合、名前と値は等号("=")でスペースなしで区切る必要があります。オプションで、空の文字列を指定できます。
--foo --foo= --foo="" --foo=bar --foo="bar then baz" --foo=bar,baz,biz
-foo --foo bar --foo = bar --foo=bar --foo=baz --foo=biz
コマンドラインで "--
" オプションプレフィックスなしで指定されたすべての引数は、「非オプション引数」と見なされ、CommandLineArgs.getNonOptionArgs()
メソッドで利用可能になります。
public static void main(String[] args) { PropertySource<?> ps = new SimpleCommandLinePropertySource(args); // ... }完全な一般的な使用例については、
CommandLinePropertySource
を参照してください。 より完全な機能を備えたコマンドライン解析が必要な場合は、提供されている JOptCommandLinePropertySource
の使用を検討するか、選択したコマンドライン解析ライブラリに対して独自の CommandLinePropertySource
を実装します。
CommandLinePropertySource
, JOptCommandLinePropertySource
PropertySource.StubPropertySource
COMMAND_LINE_PROPERTY_SOURCE_NAME, DEFAULT_NON_OPTION_ARGS_PROPERTY_NAME
logger, name, source
コンストラクターと説明 |
---|
SimpleCommandLinePropertySource(StringSE... args) デフォルト名を持ち、コマンドライン引数の指定された String[] を基にした新しい SimpleCommandLinePropertySource を作成します。 |
SimpleCommandLinePropertySource(StringSE name, StringSE[] args) 指定された名前を持ち、指定された String[] のコマンドライン引数を基にした新しい SimpleCommandLinePropertySource を作成します。 |
修飾子と型 | メソッドと説明 |
---|---|
protected boolean | containsOption(StringSE name) コマンドラインから解析されたオプション引数のセットに、指定された名前のオプションが含まれているかどうかを返します。 |
protected ListSE<StringSE> | getNonOptionArgs() コマンドラインから解析された非オプション引数のコレクションを返します。 |
protected ListSE<StringSE> | getOptionValues(StringSE name) 指定された名前を持つコマンドラインオプションに関連付けられた値のコレクションを返します。 |
StringSE[] | getPropertyNames() オプション引数のプロパティ名を取得します。 |
containsProperty, getProperty, setNonOptionArgsPropertyName
equals, getName, getSource, hashCode, named, toString
cloneSE, finalizeSE, getClassSE, notifySE, notifyAllSE, waitSE, waitSE, waitSE
public SimpleCommandLinePropertySource(StringSE... args)
String[]
を基にした新しい SimpleCommandLinePropertySource
を作成します。public StringSE[] getPropertyNames()
EnumerablePropertySource<org.springframework.core.env.CommandLineArgs>
の getPropertyNames
protected boolean containsOption(StringSE name)
CommandLinePropertySource
CommandLinePropertySource<org.springframework.core.env.CommandLineArgs>
の containsOption
@Nullable protected ListSE<StringSE> getOptionValues(StringSE name)
CommandLinePropertySource
[]
)["bar"]
)["bar", "baz"]
)null
を返します CommandLinePropertySource<org.springframework.core.env.CommandLineArgs>
の getOptionValues
protected ListSE<StringSE> getNonOptionArgs()
CommandLinePropertySource
null
。CommandLinePropertySource<org.springframework.core.env.CommandLineArgs>
の getNonOptionArgs