|
This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Shell 4.0.4! |
Confirmation
The confirmation component asks a user for a simple confirmation. It is essentially a yes-or-no question.
@Component
public class ComponentCommands {
private final Terminal terminal;
private final ResourceLoader resourceLoader;
private final TemplateExecutor templateExecutor;
public ComponentCommands(Terminal terminal, ResourceLoader resourceLoader,
TemplateExecutor templateExecutor) {
this.terminal = terminal;
this.resourceLoader = resourceLoader;
this.templateExecutor = templateExecutor;
}
@Command(name = "component confirmation", description = "Confirmation input", group = "Components")
public String confirmationInput(@Option(defaultValue = "false") boolean no) {
ConfirmationInput component = new ConfirmationInput(terminal, "Enter value", !no);
component.setResourceLoader(resourceLoader);
component.setTemplateExecutor(templateExecutor);
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:
| Key | Description |
|---|---|
|
The default value — either |
|
The parent context variables (see TextComponentContext Template Variables). |