I am looking at the documentation where I see to make a string component I need to give the component the terminal at instantiation, then set the resource loader and template executor. Using the provided documentation as a template works just fine, for now, but this appears to be using legacy annotation, which means it is not future-proofed.
Is there a way to create components without falling back on legacy code?
@ShellComponent
public class ComponentCommands extends AbstractShellComponent {
@ShellMethod(key = "component string", value = "String input", group = "Components")
public String stringInput(boolean mask) {
StringInput component = new StringInput(getTerminal(), "Enter value", "myvalue");
component.setResourceLoader(getResourceLoader());
component.setTemplateExecutor(getTemplateExecutor());
if (mask) {
component.setMaskCharacter('*');
}
StringInputContext context = component.run(StringInputContext.empty());
return "Got value " + context.getResultValue();
}
}
I’ve read thru the documentation, which seems to have been written for 2.x. The org.springframework.shell.command packages don’t appear to have an analog to o.s.s.standard.AbstractShellComponent. I’ve tried auto-wiring in the CommandContext and Springboot Application context for the resource loader, but I’m not sure where I’d find the template executor. I’d like to see a way to initialize the components without needing to rely on the o.s.s.standard package.
E.J. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.