click icon indicating copy to clipboard operation
click copied to clipboard

Provide suggestions for misspelled subcommands

Open dionhaefner opened this issue 1 year ago • 2 comments

Example app:

import click

@click.group()
def cli():
    pass

@cli.command()
@click.option("--name", default="World", help="Name of the person to greet.")
def hello(name):
    click.echo(f"Hello, {name}!")

@cli.command()
def goodbye():
    click.echo("Goodbye!")

if __name__ == "__main__":
    cli()

Providing suggestions works well for options:

$ python clickfoo.py hello --namee
Usage: clickfoo.py hello [OPTIONS]
Try 'clickfoo.py hello --help' for help.

Error: No such option: --namee Did you mean --name?

But not for subcommands:

$ python clickfoo.py hellow
Usage: clickfoo.py [OPTIONS] COMMAND [ARGS]...
Try 'clickfoo.py --help' for help.

Error: No such command 'hellow'.

Desired output:

$ python clickfoo.py hellow
Usage: clickfoo.py [OPTIONS] COMMAND [ARGS]...
Try 'clickfoo.py --help' for help.

Error: No such command 'hellow'. Did you mean `hello`?

Is this something that can be done with click?

dionhaefner avatar Aug 12 '24 09:08 dionhaefner

@davidism Can this be done? If so, I will add your suggestion to the docs.

Rowlando13 avatar Apr 06 '25 00:04 Rowlando13

FWIW, this is the workaround we use now, which works well for our needs.

dionhaefner avatar Apr 07 '25 08:04 dionhaefner