click-contrib / click-default-group

Extends click.Group to invoke a command without explicit subcommand name.
BSD 3-Clause "New" or "Revised" License
73 stars 17 forks source link

Stop use default command on complition #22

Open y-marui opened 2 years ago

y-marui commented 2 years ago

If _{prog_name}_COMPLETE is set, the click will execute completion instead of normal flow. On completion, adding the default command name to arg cause trouble.

pneff commented 1 year ago

Hi @sublee

I just came across this one in my attempt to implement auto-completion for simonw/llm (in simonw/llm#261). The proposed fix does work in that case as well.

Can I add anything to this pull request to get it merged? E.g. test coverage?

In the case of the LLM tool I observed the following. Without the fix, no completion is output:

$ env COMP_WORDS="llm" COMP_CWORD=1 _LLM_COMPLETE=bash_complete llm
(no_output)

Once I apply the fix, it works:

$ env COMP_WORDS="llm" COMP_CWORD=1 _LLM_COMPLETE=bash_complete llm
plain,aliases
plain,chat
plain,collections
plain,embed
plain,embed-models
plain,embed-multi
plain,install
plain,keys
plain,logs
plain,models
plain,openai
plain,plugins
plain,prompt
plain,similar
plain,templates
plain,uninstall