click-didyoumean
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.
Warnings
- gotcha When combining multiple Click group sources, you must use `DYMCommandCollection` instead of `DYMGroup`.
- gotcha The default number of suggestions (max_suggestions) and similarity cutoff (cutoff) might not be ideal for all applications.
- 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.
- gotcha The library officially supports Python 3.8 and above, as indicated in its `pyproject.toml`.
Install
-
pip install click-didyoumean
Imports
- DYMGroup
from click_didyoumean import DYMGroup
- DYMCommandCollection
from click_didyoumean import DYMCommandCollection
Quickstart
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()