click-didyoumean

raw JSON →
0.3.1 verified Tue May 12 auth: no python install: verified quickstart: stale

This library enables a 'did-you-mean' suggestion feature, similar to Git, for Click-based command-line interfaces. It provides an extended `Group` and `CommandCollection` class to automatically suggest correct commands for mistyped inputs. It is currently at version 0.3.1 and is infrequently updated.

pip install click-didyoumean
error ModuleNotFoundError: No module named 'click_didyoumean'
cause The 'click-didyoumean' package has not been installed in your Python environment, or your Python interpreter cannot find it.
fix
Install the package using pip: pip install click-didyoumean
error ModuleNotFoundError: No module named 'click'
cause The 'click' library, which 'click-didyoumean' depends on, is not installed or cannot be found by your Python environment.
fix
Install the 'click' package: pip install click (This is usually installed automatically with click-didyoumean, but might be missing in some specific setups or if click was uninstalled separately).
error Error: No such command 'mistyped_command'.
cause This Click error appears when a command is misspelled and 'click-didyoumean' has not been correctly integrated into your Click application (e.g., by forgetting to use `cls=DYMGroup` or `DYMCommandCollection`). The library's purpose is to add 'Did you mean?' suggestions to this specific error message.
fix
Ensure your Click group uses the DYMGroup class: @click.group(cls=DYMGroup) or that you are using DYMCommandCollection correctly for collections. Make sure you have imported DYMGroup or DYMCommandCollection from click_didyoumean.
gotcha When combining multiple Click group sources, you must use `DYMCommandCollection` instead of `DYMGroup`.
fix Instead of decorating a group, create an instance of `DYMCommandCollection` and pass your existing `click.Group` objects as `sources`. Example: `cli = DYMCommandCollection(sources=[cli1, cli2])`.
gotcha The default number of suggestions (max_suggestions) and similarity cutoff (cutoff) might not be ideal for all applications.
fix You can configure `max_suggestions` (default 3) and `cutoff` (default 0.5) when initializing `DYMGroup` or `DYMCommandCollection` to fine-tune the suggestion behavior. For example: `@click.group(cls=DYMGroup, max_suggestions=5, cutoff=0.7)`.
gotcha The library relies on Click's internal group and command handling. Major updates to Click could potentially introduce breaking changes in how these extensions integrate.
fix Always test `click-didyoumean` functionality after upgrading `Click` to a new major version. Keep `click-didyoumean` updated to its latest release.
gotcha The library officially supports Python 3.8 and above, as indicated in its `pyproject.toml`.
fix Ensure your project uses Python 3.8 or newer. While older PyPI metadata might suggest Python >=3.6.2, the current development points to 3.8+.
python os / libc status wheel install import disk
3.10 alpine (musl) wheel - 0.07s 18.6M
3.10 alpine (musl) - - 0.06s 18.6M
3.10 slim (glibc) wheel 1.5s 0.04s 19M
3.10 slim (glibc) - - 0.04s 19M
3.11 alpine (musl) wheel - 0.11s 20.6M
3.11 alpine (musl) - - 0.11s 20.5M
3.11 slim (glibc) wheel 1.7s 0.08s 21M
3.11 slim (glibc) - - 0.08s 21M
3.12 alpine (musl) wheel - 0.09s 12.4M
3.12 alpine (musl) - - 0.09s 12.4M
3.12 slim (glibc) wheel 1.5s 0.08s 13M
3.12 slim (glibc) - - 0.08s 13M
3.13 alpine (musl) wheel - 0.08s 12.1M
3.13 alpine (musl) - - 0.10s 12.0M
3.13 slim (glibc) wheel 1.5s 0.08s 13M
3.13 slim (glibc) - - 0.08s 13M
3.9 alpine (musl) wheel - 0.06s 18.0M
3.9 alpine (musl) - - 0.08s 18.0M
3.9 slim (glibc) wheel 1.8s 0.06s 18M
3.9 slim (glibc) - - 0.05s 18M

To enable the 'did-you-mean' feature, simply pass `cls=DYMGroup` to your `click.group` decorator. For more complex applications using `CommandCollection`, substitute `DYMCommandCollection`.

import click
from click_didyoumean import DYMGroup

@click.group(cls=DYMGroup)  # Apply DYMGroup as the class for your main CLI group
def cli():
    """A simple CLI with did-you-mean suggestions."""
    pass

@cli.command()
def deploy():
    """Deploys the application."""
    click.echo("Deploying application...")

@cli.command()
def delete():
    """Deletes resources."""
    click.echo("Deleting resources...")

@cli.command()
def devops():
    """Runs devops tasks."""
    click.echo("Running devops tasks...")

if __name__ == '__main__':
    # Example usage (run from terminal, e.g., `python your_cli.py deplo`) will suggest `deploy`
    cli()