英文:
Spring shell 3 - StringInputContext not prompting for input?
问题
I set up a new project using spring-boot(-shell) 3.0.3
and I'm just trying to capture some inputs and return them. When I pass in the arguments using ShellOption everything works fine, but I wanted to try out a bit more of the framework and use the input components.
However I'm getting no error when running it from powershell, yet I am also not getting prompted for my input despite following the documentation at https://docs.spring.io/spring-shell/docs/3.0.x/docs/#using-shell-components albeit with the caveat of using the new StringInputContext
location since the one in the docs is seemingly now an embedded class.
Can anyone help point me in the right direction, here's a simplified snippet:
@ShellComponent
public class SomeCommand extends AbstractShellComponent {
@ShellMethod(value = "Ask and return2")
public String ask2() {
StringInput component = new StringInput(getTerminal(), "What to return?", "");
component.setResourceLoader(getResourceLoader());
component.setTemplateExecutor(getTemplateExecutor());
StringInput.StringInputContext context = component.run(StringInput.StringInputContext.empty());
return context.getResultValue();
}
}
I saw https://stackoverflow.com/questions/25991910/spring-shell-command-prompt-exits-immediately-does-not-await-user-input but I am not opening the prompt from within IntelliJ, but from within powershell & cmd prompt.
英文:
I set up a new project using spring-boot(-shell) 3.0.3
and I'm just trying to capture some inputs and return them. When I pass in the arguments using ShellOption everything works fine, but I wanted to try out a bit more of the framework and use the input components.
However I'm getting no error when running it from powershell, yet I am also not getting prompted for my input despite following the documentation at https://docs.spring.io/spring-shell/docs/3.0.x/docs/#using-shell-components albeit with the caveat of using the new StringInputContext
location since the one in the docs is seemingly now an embedded class.
Can anyone help point me in the right direction, here's a simplified snippet:
@ShellComponent
public class SomeCommand extends AbstractShellComponent {
@ShellMethod(value = "Ask and return2")
public String ask2() {
StringInput component = new StringInput(getTerminal(), "What to return?", "");
component.setResourceLoader(getResourceLoader());
component.setTemplateExecutor(getTemplateExecutor());
StringInput.StringInputContext context = component.run(StringInput.StringInputContext.empty());
return context.getResultValue();
}
}
I saw https://stackoverflow.com/questions/25991910/spring-shell-command-prompt-exits-immediately-does-not-await-user-input but I am not opening the prompt from within IntelliJ, but from within powershell & cmd prompt.
答案1
得分: 1
依赖关系很少:在*nix系统上,您可以使用JLine而不依赖任何库,但为了支持Windows或更高级的用法,您需要添加Jansi或JNA库之一。
英文:
The dependencies are minimal: you may use JLine without any dependency on *nix systems, but in order to support windows or more advanced usage, you will need to add either Jansi or JNA library.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论