picocli
picocli copied to clipboard
Feature Request: fish completion
I think fish completion is generally much simpler than bash e.g. see examples below with baked in completions "atlassian github" etc. But the functions at the top actually use the command itself to generate context sensitive completions by calling the code inside the app. Good for URLs etc.
https://github.com/yschimke/cooee-cli/blob/master/src/dist/fish/cooee.fish
function __fish_complete_cooee_command
cooee --fish-complete (commandline -ct)
end
function __fish_complete_add_command
cooee --option-complete (commandline -ct)
end
function __fish_complete_remove_command
cooee --option-complete (commandline -ct)
end
complete -c cooee -x -d 'Cooee CLI' -a '(__fish_complete_cooee_command)'
complete -c cooee -l debug -d 'Show debug output'
complete -c cooee -s h -l help -d 'Help options'
complete -c cooee -l login -d 'Login and link account'
complete -c cooee -l logout -d 'Unlink account'
complete -c cooee -s V -l version -d 'Output version and exit'
complete -c cooee -l repl -d 'REPL'
complete -c cooee -l list -d 'List apps'
complete -c cooee -l add -x -d 'Add app' -a '(cooee --option-complete add)'
complete -c cooee -l remove -x -d 'Remove app' -a '(cooee --option-complete remove)'
complete -c cooee -l token -x -d 'Provide specific authorization token'
#complete -c cooee -l tokenSet -x -d 'Set a named authorization token'
complete -c cooee -l authorize -x -d 'Authorize a provider' -a "atlassian github google trello strava"
complete -c cooee -l option-complete -x -a "option-complete command-complete authorize" -d 'Complete possible options'
complete -c cooee -l command-complete -d 'Complete possible command'
Thanks for the suggestion! Fish looks very interesting.
Do you think you’ll be able to provide a pull request?
@remkop Fair question, It's unlikely I will in next 6 months due to
- I have working code that is app specific
- I have other project commitments, work+personal projects+OkHttp
- I'm hesitent to build something like this and not support it. It would be a gamble that utility proved itself enough to gain support within existing users.
So feel free to close this and #726 but it's so palpably close to what I need to delete a tone of code in my own apps.
Feel free to close, this is a suggestion, I don't have plans to actively work on this.
No worries!
It is great if people can contribute a PR, so I always ask :-)
I wasn’t aware of fish shell. I had a quick look and it may be quite straightforward to generate a completion script from the picocli model. It’s still a good suggestion and I don’t plan to close the ticket.
It's a great choice for your interactive (only) shell. And in the examples above you can see how sensible the completion logic is.
complete -c cooee -s V -l version -d 'Output version and exit'
-s is short option, -l is long option with -- prefix, and -d is description.
Yes that looks straightforward.
I need to look a bit further to see how subcommands (and nested sub-subcommands) are handled, and whether there's a facility for completing options that don't look like POSIX short options or GNU long options (like java -version
), but the above looks promising.
Update:
Useful links:
- https://fishshell.com/docs/current/cmds/complete.html?highlight=completion
- https://stackoverflow.com/questions/16657803/creating-autocomplete-script-with-sub-commands
- https://github.com/clap-rs/clap/issues/685
- https://blog.gobuffalo.io/tab-completion-script-for-buffalo-in-fish-shell-c8bad3705d32
Are there any news?
@benkeil I haven’t looked at this. My time available to spend on picocli is unfortunately extremely limited.
Pull requests are very welcome. 😅
I've made some very dirty proof of concept realization for fish completion in #1925
It successfully generated completion for my simple app, but it's definitely not universal at the moment. I think now it works only for apps with sub-commands.
If anybody interested, they can try to generate completion for their app from #1925