このバージョンはまだ開発中であり、まだ安定しているとは見なされていません。最新の安定バージョンについては、Spring Shell 3.4.1 を使用してください! |
文字列入力
The string input component asks a user for simple text input, optionally masking values if the content contains something sensitive. The input can also be required (at least 1 char).
The following listing shows an example:
public class ComponentCommands {
@Command(name = "component string", description = "String input", group = "Components")
public String stringInput(boolean mask) {
StringInput component = new StringInput(getTerminal(), "Enter value", "myvalue");
ResourceLoader resourceLoader = null; // getResourceLoader();
TemplateExecutor templateExecutor = null; // getTemplateExecutor();
component.setResourceLoader(resourceLoader);
component.setTemplateExecutor(templateExecutor);
if (mask) {
component.setMaskCharacter('*');
}
StringInputContext context = component.run(StringInputContext.empty());
return "Got value " + context.getResultValue();
}
}次のスクリーンキャストは、文字列入力コンポーネントからの一般的な出力を示しています。
コンテキストオブジェクトは StringInputContext です。次の表に、そのコンテキスト変数を示します。
| キー | 説明 |
|---|---|
| 設定されている場合のデフォルト値。それ以外の場合は null。 |
| マスクされた入力値 |
| マスクされた結果値 |
| マスク文字 (設定されている場合)。それ以外の場合は null。 |
|
|
|
|
| 親コンテキスト変数 ( TextComponentContext テンプレート変数を参照)。 |