/click-fuzzy

Fuzzy subcommand matching for click

Primary LanguagePythonMIT LicenseMIT

Fuzzy Commands for Click

Fuzzy command matching and aliases for click

version license

Allows use of automatic prefix aliases and matching small typos:

$ command h
WARNING: Assuming 'h' is short for 'hello'
Hello world!

$ command helol
WARNING: Assuming 'helol' is slang for 'hello'
Hello world!

Explicit aliases can also be defined:

$ command --help
Usage: command [OPTIONS] COMMAND [ARGS]...

Commands:
  hello, hi  The traditional greeting

$ command hi --help
Usage: command hello [OPTIONS]

Install

$ pip install click-fuzzy

Usage

from click_fuzzy import FuzzyCommandGroup

@click.group(cls=FuzzyCommandGroup)
def main(...):
    ...

@main.command("hello")
@main.alias("hi")
def hello():
    ...

That's it. Everything else happens automatically.

If you only want explicit aliases, and don't want automatic prefix or fuzzy matching, use AliasedCommandGroup instead of FuzzyCommandGroup:

License

Fuzzy Commands is copyright Amethyst Reese, and licensed under the MIT license.