Spring Shell 3 – StringInputContext未提示输入?

huangapple go评论56阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年3月1日 14:34:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/75600260.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定