Automatically enable tab autocompletion for shells in Click CLI applications.
Maintained. Last release 4 months ago, commits in 1 of the last 26 weeks. Weaker on commit activity and release cadence.
pip install auto-click-autoREADME as published on PyPI with version 0.1.6.
auto-click-auto
Automatically enable tab autocompletion for shells in Click CLI applications.
auto-click-auto is a small Python library that is used to quickly and easily add tab shell completion support for
Bash (version 4.4 and up), Zsh, and Fish, for Click CLI programs.
Installation
pip install auto-click-auto
Usage
There are two functions that auto-click-auto makes available: enable_click_shell_completion (general use)
and enable_click_shell_completion_option (to be used as a decorator).
In the function docstrings, you can find a detailed analysis of the available parameters and their use.
auto-click-auto will print the relative output when a shell completion is activated for the first time and can be
set to an extra verbosity if you want to display information about already configured systems or debug.
Here are some typical ways to enable autocompletion with auto-click-auto:
- Check on every run of the CLI program if autocompletion is configured and enable it in case that it is not
This way you can seamlessly enable shell autocompletion without the user having to run any extra commands.
Example:
import click
from auto_click_auto import enable_click_shell_completion
from auto_click_auto.constants import ShellType
@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}!")
enable_click_shell_completion(
program_name="example-1", shells={ShellType.BASH, ShellType.FISH},
)