确认
确认组件向用户询问一个简单的确认。它本质上是一个是或否的问题。
@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();
}
}
以下屏幕截图显示了来自确认组件的典型输出
上下文对象是ConfirmationInputContext
。下表描述了它的上下文变量
键 | 描述 |
---|---|
|
默认值 — |
|
父上下文变量 (参见 TextComponentContext 模板变量)。 |