Closed DmitryAndreyeff closed 5 years ago
I believe so, yes.
Please take a look at the picocli-shell-jline2
module: it provides a component to integrate picocli commands with the jline
interactive shell. By default this component generates completion candidates based on the options and positional parameters for the command. It passes these candidates to a JLine API, and JLine will display these candidates when the end user hits <TAB>
in the shell.
Each option or positional parameter of a picocli @Command
can have custom completion candidates: all you need to do is specify a class that implements Iterable<String>
. The simplest thing to do is to subclass ArrayList
with some fixed values, but a more sophisticated completion candidates provider could return all files in the current directory, etc.
The rest is providing your business logic in the picocli commands, and perhaps some polishing to make the JLine interface look and feel the way you want.
Thank you for the quick response! I will look into it.
@DmitryAndreyeff Were you able to make progress? Do you have follow-up questions, or can this ticket be closed?
Hi, I don't have questions for now. Thank you for assistance!
@remkop Having a lot of fun with this module 💯 !
One question though, why did you go with jline2 vs jline3? Was it a licensing concern?
JLine2 requires only Java5, like picocli. Also, I had the Completer code ready from my contributions to the Micronaut CLI.
JLine3 requires Java 8. Planning to add a JLine 3 module later.
If you feel like contributing a JLine 3-based Completer, we can add another module for JLine 3. Pull requests welcome!
Hi! I'm looking for a way to build interactive shell for managing the configuration of a large system. The configuration has hierarchical structure, and I would like to provide user experience very similar to file system navigation where most used commands will be ls and cd. I would like to have autocompletion based on current "directory" content, and shell prompt to change dynamically to reflect current path in the hierarchy. Is this achievable with picocli? Thanks!