alecthomas / kingpin

CONTRIBUTIONS ONLY: A Go (golang) command line and flag parser
MIT License
3.5k stars 272 forks source link

Do not pass command name to `--completion-bash` argument in ZSH template #339

Closed gzdunek closed 1 year ago

gzdunek commented 1 year ago

Sub-commands and sub-commands flags are not autocompleted correctly in ZSH. This is because in the ZSH template, the argument passed to --completion-bash begins with the command name.

The issue can be reproduced in _examples/completion: running ./completion nc -- returns identical autocompletion values as the ./completion -- alone.

Incorrect invocation of --completion-bash with the command name:

grzegorz@mbp kingpin % ./completion --completion-bash ./completion nc -- 
--help
--flag-1
--flag-2

Fixed invocation of --completion-bash without the command name:

grzegorz@mbp kingpin % ./completion --completion-bash nc --             
--nop-flag
--host
--port
--format
--host-with-multi
--host-with-multi-options
--format-with-override-1
--format-with-override-2
--help
--flag-1
--flag-2

This PR fixes the passed arguments by starting from the second word (just like the bash template).

alecthomas commented 1 year ago

Thanks!