auto-click-auto

0.1.5 · active · verified Thu Apr 16

auto-click-auto is a small Python library (current version 0.1.5) that automatically enables tab shell completion for Bash (version 4.4 and up), Zsh, and Fish in Click CLI applications. It aims to simplify the setup of shell completion compared to Click's native methods by offering a seamless, automatic configuration. The project has a low-to-moderate release cadence, with the latest update on June 26, 2024.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates integrating `auto-click-auto` into a basic Click CLI. The `enable_click_shell_completion` function is called at the end of the main CLI function, providing the program's executable name and a set of `ShellType` enums for which to enable completion.

import click
from auto_click_auto import enable_click_shell_completion
from auto_click_auto.constants import ShellType
import os # Only for example program_name, not strictly for auto-click-auto

@click.command()
@click.option('--count', default=1, help='Number of greetings.')
@click.option('--name', prompt='Your name', help='The person to greet.')
def hello(count, name):
    """Simple program that greets NAME for a total of COUNT times."""
    for x in range(count):
        click.echo(f"Hello {name}!")
    
    # Automatically enable shell completion for specified shells
    # Replace 'my-cli-app' with the actual executable name of your CLI
    # For testing, you might use 'python -m my_cli_module' as the program_name
    enable_click_shell_completion(
        program_name=os.path.basename(__file__).replace('.py', ''), # Derives name from script, adjust for packaged CLIs
        shells={ShellType.BASH, ShellType.ZSH, ShellType.FISH},
        # For debugging, add debug=True
    )

if __name__ == '__main__':
    hello()

view raw JSON →