remkop / picocli

Picocli is a modern framework for building powerful, user-friendly, GraalVM-enabled command line apps with ease. It supports colors, autocompletion, subcommands, and more. In 1 source file so apps can include as source & avoid adding a dependency. Written in Java, usable from Groovy, Kotlin, Scala, etc.
https://picocli.info
Apache License 2.0
4.91k stars 423 forks source link

Feature Request: fish completion #725

Open yschimke opened 5 years ago

yschimke commented 5 years ago

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'
remkop commented 5 years ago

Thanks for the suggestion! Fish looks very interesting.

Do you think you’ll be able to provide a pull request?

yschimke commented 5 years ago

@remkop Fair question, It's unlikely I will in next 6 months due to

1) I have working code that is app specific 2) I have other project commitments, work+personal projects+OkHttp 3) 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.

remkop commented 5 years ago

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.

yschimke commented 5 years ago

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.

remkop commented 5 years ago

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:

benkeil commented 2 years ago

Are there any news?

remkop commented 2 years ago

@benkeil I haven’t looked at this. My time available to spend on picocli is unfortunately extremely limited.

Pull requests are very welcome. 😅

volkov commented 1 year ago

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