This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Shell 3.3.1!

String Input

The string input component asks a user for simple text input, optionally masking values if the content contains something sensitive. The following listing shows an example:

@ShellComponent
public class ComponentCommands extends AbstractShellComponent {

	@ShellMethod(key = "component string", value = "String input", group = "Components")
	public String stringInput(boolean mask) {
		StringInput component = new StringInput(getTerminal(), "Enter value", "myvalue");
		component.setResourceLoader(getResourceLoader());
		component.setTemplateExecutor(getTemplateExecutor());
		if (mask) {
			component.setMaskCharacter('*');
		}
		StringInputContext context = component.run(StringInputContext.empty());
		return "Got value " + context.getResultValue();
	}
}

The following screencast shows typical output from a string input component:

The context object is StringInputContext. The following table lists its context variables:

Table 1. StringInputContext Template Variables
Key Description

defaultValue

The default value, if set. Otherwise, null.

maskedInput

The masked input value

maskedResultValue

The masked result value

maskCharacter

The mask character, if set. Otherwise, null.

hasMaskCharacter

true if a mask character is set. Otherwise, false.

model

The parent context variables (see TextComponentContext Template Variables).