click-didyoumean

Adds git-style Did you mean suggestions to Click command-line groups

Library
PyPI
v0.3.1
101stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
34/100Needs Attention
Development Activity0
Maintenance20
Community44
Maturity60
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
73/100Good
Architecture68
Code Quality70
Innovation60
Learning Curve92

click-didyoumean is a small extension for the Click CLI framework that replicates git’s familiar “did you mean” behavior: when a user mistypes a subcommand, instead of just failing with a usage error, the CLI suggests the closest-matching registered command names.

It works by providing DYMGroup and DYMCommandCollection mixin classes that override Click’s resolve_command method, using Python’s built-in difflib.get_close_matches to compute similarity against all registered command names and appending matches above a configurable similarity cutoff to the raised UsageError. Adopting it requires no changes beyond passing cls=DYMGroup to @click.group(), making it a common ergonomic add-on for any multi-command Click-based CLI tool.

What You Get

  • A DYMGroup drop-in replacement for click.Group that adds did-you-mean suggestions on unmatched subcommands
  • A DYMCommandCollection variant for CLIs composed from multiple click.Group sources
  • Configurable max_suggestions (default 3) and cutoff (default 0.5) similarity parameters
  • Zero additional dependencies beyond Click itself and Python’s standard-library difflib

Common Use Cases

  • Improving UX on multi-command CLI tools by suggesting corrections for mistyped subcommands
  • Adding git-style ergonomics to internal developer tools built with Click
  • Providing helpful suggestions in CLIs composed from several click.Group sources via DYMCommandCollection

Under The Hood

Architecture - The entire library is a DYMMixin class that overrides Click’s resolve_command() method: it first attempts the normal resolution via super(), and on a caught UsageError, calls difflib.get_close_matches() against the group’s registered command list, appending any matches above the cutoff threshold to the error message before re-raising; DYMGroup and DYMCommandCollection simply combine this mixin with click.Group and click.CommandCollection respectively. Tech Stack - Pure Python with a single runtime dependency on click itself, using only the standard-library difflib module for similarity matching — no third-party fuzzy-matching library is needed. Code Quality - The package has one test file covering the mixin’s suggestion behavior; the single-module implementation (src/click_didyoumean/__init__.py) is fully type-annotated and includes docstrings on every public class and method. API Design - Adoption requires only passing cls=DYMGroup to an existing @click.group() decorator, with two optional keyword arguments (max_suggestions, cutoff) for tuning — a minimal-friction, drop-in API that needs no restructuring of an existing Click CLI.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search