Package: auto-click-auto
auto-click-autoAutomatically enable tab autocompletion for shells in Click CLI applications.auto-click-autois a small Python library that is used to quickly and easily add tab shell completion support forBash(version 4.4 and up),Zsh, andFish, forClickCLI programs.Installationpip install auto-click-autoUsageThere are two functions thatauto-click-automakes available:enable_click_shell_completion(general use)
andenable_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-autowill 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 withauto-click-auto:Check on every run of the CLI program if autocompletion is configured and enable it in case that it is notThis way you can seamlessly enable shell autocompletion without the user having to run any extra commands.Example:importclickfromauto_click_autoimportenable_click_shell_completionfromauto_click_auto.constantsimportShellType@click.command()@click.option('--count',default=1,help='Number of greetings.')@click.option('--name',prompt='Your name',help='The person to greet.')defhello(count,name):"""Simple program that greets NAME for a total of COUNT times."""forxinrange(count):click.echo(f"Hello{name}!")enable_click_shell_completion(program_name="example-1",shells={ShellType.BASH,ShellType.FISH},)Make shell completion a Click command optionExample:importclickfromauto_click_autoimportenable_click_shell_completion_option@click.command()@enable_click_shell_completion_option(program_name="example-2")@click.option('--count',default=1,help='Number of greetings.')@click.option('--name',prompt='Your name',help='The person to greet.')defhello(count,name):"""Simple program that greets NAME for a total of COUNT times."""forxinrange(count):click.echo(f"Hello{name}!")Make shell completion a command (or subcommand of a group)This implementation option might be useful if you already have a "configuration" command in your CLI program.Example:importclickfromauto_click_autoimportenable_click_shell_completionfromauto_click_auto.constantsimportShellType@click.group()defcli():"""Simple CLI program."""pass@cli.command()@click.option('--count',default=1,help='Number of greetings.')@click.option('--name',prompt='Your name',help='The person to greet.')defhello(count,name):"""Simple command that greets NAME for a total of COUNT times."""forxinrange(count):click.echo(f"Hello{name}!")@cli.group()defconfig():"""Program configuration."""pass@config.command()defshell_completion():"""Activate shell completion for this program."""enable_click_shell_completion(program_name="example-3",shells={ShellType.BASH,ShellType.FISH,ShellType.ZSH},verbose=True,)ExamplesTo run the examples, fork this repository and follow the instructions athttps://github.com/KAUTH/auto-click-auto/tree/main/examples.Implementationauto-click-autoenables tab autocompletion based onClick's documentation.Nameauto-click-auto, as the name suggests, _auto_matically provides tab _auto_completion support forClickCLI
applications.Whyauto-click-auto?In the search for other tools that enable shell completion for Click we come across a lot of repositories with example
code or gists. This adds a bit of complexity to adapting the code and adding it to our use case quickly.A very nice tool isclick-completion, which provides enhanced
completion for Click.click-completion:Adds automatic completion support for fish, Zsh, Bash and PowerShellCurrently, has one extra dependency, in addition to ClickCan customize the completionHowever, it is important to note that this repository could be duplicating currently integrated Click functionality and
might need to be archived. You can monitor the issuehere.In summary,auto-click-auto:Has one specific purpose, it "automatically" enables shell completion for Click programsDoes not have any 3rd party dependencies, besides ClickProvides an option for seamless enabling of the shell completionComes ready with ways to add shell completion as a command option or subcommandHas simple examples of how to quickly use the libraryChangeloghttps://github.com/KAUTH/auto-click-auto/blob/main/CHANGELOG.mdContributingYou can always submit a PR if you want to suggest improvements or fix issues.
Check out the open issues athttps://github.com/KAUTH/auto-click-auto/issues.