click-contrib / click-completion

Add or enhance bash, fish, zsh and powershell completion in Click
MIT License
288 stars 32 forks source link

Add autocompletion callback for Options #27

Open chrisjsewell opened 5 years ago

chrisjsewell commented 5 years ago

As explained here in the Click documentation, and implemented here: https://github.com/pallets/click/blob/93b1699cde5fbafe8a237f8f0d21c8f687b78f2f/click/_bashcomplete.py#L185, click Parameters have an autocompletion argument that is currently not supported in click-completion. This small addition rectifies that :)

Konubinix commented 4 years ago

To summarize what exists for now:

By chance, the Choice class has a complete method that provided the completion against the choice.

What is counter intuitive in the code of click-completion is that we call choice the result of the method complete. That explains why you confounded with the Choice class.

In my mind, the more sensible is to first call get_user_autocompletions (instezd of rewriting part of it in click-completion) , then add the results of the complete method of the type.

Also, I find getattr(optctx, "autocompletion", None) is not None shorter and more readable than hasattr(optctx, 'autocompletion') and optctx.autocompletion is not None.

Konubinix commented 2 years ago

I did not follow what was done in the other PR and in click. Is this still relevant?