
Security News
CISA Extends MITRE Contract as Crisis Accelerates Alternative CVE Coordination Efforts
CISA extended MITRE’s CVE contract by 11 months, avoiding a shutdown but leaving long-term governance and coordination issues unresolved.
Automatically enable tab autocompletion for shells in Click CLI applications.
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.
pip install auto-click-auto
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
:
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},
)
Example:
import click
from auto_click_auto import enable_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.')
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}!")
This implementation option might be useful if you already have a "configuration" command in your CLI program.
Example:
import click
from auto_click_auto import enable_click_shell_completion
from auto_click_auto.constants import ShellType
@click.group()
def cli():
"""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.')
def hello(count, name):
"""Simple command that greets NAME for a total of COUNT times."""
for x in range(count):
click.echo(f"Hello {name}!")
@cli.group()
def config():
"""Program configuration."""
pass
@config.command()
def shell_completion():
"""Activate shell completion for this program."""
enable_click_shell_completion(
program_name="example-3",
shells={ShellType.BASH, ShellType.FISH, ShellType.ZSH},
verbose=True,
)
To run the examples, fork this repository and follow the instructions at https://github.com/KAUTH/auto-click-auto/tree/main/examples.
auto-click-auto
enables tab autocompletion based on Click's documentation.
auto-click-auto
, as the name suggests, _auto_matically provides tab _auto_completion support for Click CLI
applications.
auto-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 is click-completion
, which provides enhanced
completion for Click. click-completion
:
However, 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 issue here.
In summary, auto-click-auto
:
https://github.com/KAUTH/auto-click-auto/blob/main/CHANGELOG.md
You can always submit a PR if you want to suggest improvements or fix issues. Check out the open issues at https://github.com/KAUTH/auto-click-auto/issues.
FAQs
Automatically enable tab autocompletion for shells in Click CLI applications.
We found that auto-click-auto demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISA extended MITRE’s CVE contract by 11 months, avoiding a shutdown but leaving long-term governance and coordination issues unresolved.
Product
Socket's Rubygems ecosystem support is moving from beta to GA, featuring enhanced security scanning to detect supply chain threats beyond traditional CVEs in your Ruby dependencies.
Research
The Socket Research Team investigates a malicious npm package that appears to be an Advcash integration but triggers a reverse shell during payment success, targeting servers handling transactions.