StringInput masking

- Add a feature to define a mask character for StringInput
  which help when there's a need to as something sensitive.
- This masks both input and result value.
This commit is contained in:
Janne Valkealahti
2022-02-08 10:26:17 +00:00
parent e3604a5bc5
commit 2f4209785e
4 changed files with 132 additions and 10 deletions

View File

@@ -51,10 +51,13 @@ public class ComponentCommands extends AbstractShellComponent implements Resourc
}
@ShellMethod(key = "component string", value = "String input", group = "Components")
public String stringInput() {
public String stringInput(boolean mask) {
StringInput component = new StringInput(getTerminal(), "Enter value", "myvalue");
component.setResourceLoader(resourceLoader);
component.setTemplateExecutor(templateExecutor);
if (mask) {
component.setMaskCharater('*');
}
StringInputContext context = component.run(StringInputContext.empty());
return "Got value " + context.getResultValue();
}