確認

確認組件會詢問使用者一個簡單的確認。它本質上是一個是非題。

@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();
	}
}

以下螢幕錄影展示了確認組件的典型輸出

Context 物件是 ConfirmationInputContext。下表描述了其 context 變數

表 1. ConfirmationInputContext 範本變數
描述

defaultValue

預設值 — truefalse

model

父層 context 變數 (請參閱 TextComponentContext 範本變數)。