Click Completion

0.5.2 · active · verified Fri Apr 17

click-completion is a Click extension that provides shell completion for Fish, Bash, Zsh, and PowerShell. It helps users get tab-completion for their Click-based command-line interfaces. The current version is 0.5.2, and as a `click-contrib` library, it typically maintains an active but often lower-cadence release cycle, with updates often aligning with Click's own evolution.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a minimal Click application integrated with `click-completion`. It defines a root group `cli` with two commands, `hello` and `goodbye`. Calling `click_completion.init()` at the start enables the completion functionality for the CLI. To activate completion, you would typically run `python your_app.py --show-completion <shell_type>` and source the output in your shell configuration.

import click
import click_completion

# Initialize click-completion. This must be called BEFORE defining your commands
# if you want options like --show-completion to be available.
click_completion.init()

@click.group()
def cli():
    """A simple CLI demonstrating completion."""
    pass

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

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

if __name__ == '__main__':
    cli()

view raw JSON →