Closed kontrafiktion closed 6 years ago
Thank you for the PR. As far as I am concerned, this is ok. I think bash-complete doesn't mind this change for it already checks the completions start with the prefix. Just waiting for @glehmann to discuss further before merging, just in case.
I was wrong. Bash completion wont filter out the completions that don't start with the prefix.
Actually, we already have a way to provide completion customization in the init fonction of click_completion. I am realizing we did not make Choice use those.
IMHO, the fix would be to first make Choice use the click_completion matching algorithm, and then extend this matching algorithm to make it work with substring matching.
I am giving it a shot right now :-)
Actually, click_completion already provide you with this customization. With the current master, simply provide this in the beginning of your application.
from click_completion import init
def match_incomplete(choice, incomplete):
return incomplete in choice
init(match_incomplete=match_incomplete)
This won't impact only Choice, but all the completions, giving IMHO a better look and feel.
If you want only Choice to have a custom completion, then I suggest you create a new ParamType with its custom completion:
class MyChoice(click.Choice):
def complete(self, ctx, incomplete):
return [c for c in self.choices if incomplete in c]
@kontrafiktion How did it go?
Works for me. You can forget my PR
Fixes #13