For the latest stable version, please use Spring Shell 3.4.0!

Confirmation

The confirmation component asks a user for a simple confirmation. It is essentially a yes-or-no question.

@ShellComponent
public class ComponentCommands extends AbstractShellComponent {

	@ShellMethod(key = "component confirmation", value = "Confirmation input", group = "Components")
	public String confirmationInput(boolean no) {
		ConfirmationInput component = new ConfirmationInput(getTerminal(), "Enter value", !no);
		component.setResourceLoader(getResourceLoader());
		component.setTemplateExecutor(getTemplateExecutor());
		ConfirmationInputContext context = component.run(ConfirmationInputContext.empty());
		return "Got value " + context.getResultValue();
	}
}

The following screencast shows the typical output from a confirmation component:

The context object is ConfirmationInputContext. The following table describes its context variables:

Table 1. ConfirmationInputContext Template Variables
Key Description

defaultValue

The default value — either true or false.

model

The parent context variables (see TextComponentContext Template Variables).