click-contrib / click-completion

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

zsh completion with "inner" substrings #13

Closed kontrafiktion closed 6 years ago

kontrafiktion commented 6 years ago

I have a Choice option with the following values: "kotlin-rest-spring-boot-local", "kotlin-rest-spring-boot", "java-rest-spring-boot"

@click.option('--template', "template_key", type=click.Choice(["kotlin-rest-spring-boot-local", "kotlin-rest-spring-boot", "java-rest-spring-boot"]))
def create(template_key=None):
    pass

when I hit 'tab'for the first time at

compdummy --template <tab>

I get

compdummy --template -rest-spring

because '-rest-spring' is a common substring. Hitting 'tab' again, nothing happens because:

def choice_complete(self, ctx, incomplete):
    return [c for c in self.choices if c.startswith(incomplete)]

only checks for 'startswith'.

If I replace the above code with:

def choice_complete(self, ctx, incomplete):
    return [c for c in self.choices if incomplete in c]

everything works fine

kontrafiktion commented 6 years ago

test code:

#!/usr/bin/env python

import click
import click_completion

click_completion.init(complete_options=True)

@click.group(help)
def completion():
    """Needed for click_completion."""
    pass

@completion.command()
@click.option('--template', "template_key", type=click.Choice(["kotlin-rest-spring-boot-local", "kotlin-rest-spring-boot", "java-rest-spring-boot"]))
def create(template_key=None):
    pass

if __name__ == '__main__':
    create()
Konubinix commented 6 years ago

See the conversation in #14