Skip to main content

Latest version released on PyPi Package license

Enable git-like did-you-mean feature in click.

Example

This example is based on the official naval example from click:

$ naval shi move
Usage: naval [OPTIONS] COMMAND [ARGS]...

Error: No such command "shi".

Did you mean one of these?
    ship

Usage

Install this extension with pip:

pip install click-didyoumean

Use specific did-you-mean group class for your cli:

import click
from click_didyoumean import DYMGroup

@click.group(cls=DYMGroup)
def cli():
    pass

@cli.command()
def foo():
    pass

@cli.command()
def bar():
    pass

@cli.command()
def barrr():
    pass

if __name__ == "__main__":
    cli()

Or you it in a CommandCollection:

import click
from click_didyoumean import DYMCommandCollection

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

@cli1.command()
def foo():
    pass

@cli1.command()
def bar():
    pass

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

@cli2.command()
def barrr():
    pass

cli = DYMCommandCollection(sources=[cli1, cli2])

if __name__ == "__main__":
    cli()

Change configuration

There are two configuration for the DYMGroup and DYMCommandCollection:

Parameter

Type

Description

max_suggestions

int

Maximal number of did-you-mean suggestions

cutoff

float

Possibilities that don’t score at least that similar to word are ignored.

Examples

@cli.group(cls=DYMGroup, max_suggestions=2, cutoff=0.7)
def cli():
    pass

... or ...

cli = DYMCommandCollection(sources=[cli1, cli2], max_suggestions=2, cutoff=0.7)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

click-didyoumean-0.0.1.tar.gz (2.6 kB view details)

Uploaded Source

File details

Details for the file click-didyoumean-0.0.1.tar.gz.

File metadata

File hashes

Hashes for click-didyoumean-0.0.1.tar.gz
Algorithm Hash digest
SHA256 741fc03df7e70259d51947a32699c91427879dd864d709e8e586fc3681c94398
MD5 b43972485b4338029df1d7d055e01112
BLAKE2b-256 cd1be990329a60aaea296afc77857c0504594645068a253ab9c739cf4bcbb41d

See more details on using hashes here.

Release history Release notifications | RSS feed

0.3.1

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

0.0.3

1 file

0.0.2

1 file

This release

0.0.1 This release

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page