click-aliases is a Python library that extends Click, a popular CLI creation kit, by allowing developers to assign multiple distinct aliases to commands and groups. It addresses Click's lack of built-in 'true' command aliasing (beyond prefix matching) by providing a custom group class. The current version is 1.0.5, released in October 2024, and it generally follows a maintenance release cadence.
pip install click-aliasesVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to set up a Click CLI with `click-aliases`. The `ClickAliasedGroup` is passed as the class for the main Click group, and then individual commands can specify aliases using the `aliases` argument in the `@cli.command()` decorator.
Understand that `click-aliases` is for defining explicit, distinct alternative names for commands, not for automatically shortening command names (which Click handles to a degree).
Test thoroughly when using multiple Click extensions. For help output issues, custom `HelpFormatter` implementations or further overrides of Click's core classes might be required to integrate alias display seamlessly.
Continue using `click-aliases` or implement custom group classes as shown in Click's advanced patterns if more fine-grained control is needed. This warning is more about Click's design philosophy than a deprecation within `click-aliases`.
pip install click-aliases
pip install click
Ensure your `@click.group` decorator specifies `cls=ClickAliasedGroup` and that you import `ClickAliasedGroup` from `click_aliases`. If using `rich-click`, ensure it's version 1.9.0 or newer, or correctly compose `ClickAliasedGroup` with `rich_click.RichGroup`.
```python
from click_aliases import ClickAliasedGroup
import click
@click.group(cls=ClickAliasedGroup)
def cli():
pass
@cli.command(aliases=['my-alias', 'ma'])
def my_command():
click.echo("Hello from my_command!")
```Verify that `ClickAliasedGroup` is imported and passed as the `cls` argument to your top-level `click.group` decorator, and that aliases are provided as a list to the `aliases` keyword argument in your `@command` decorator.
```python
from click_aliases import ClickAliasedGroup
import click
@click.group(cls=ClickAliasedGroup)
def cli():
"""A CLI with aliases."""
pass
@cli.command(aliases=['hello-alias', 'h-a'])
def hello():
"""Says hello."""
click.echo("Hello!")
if __name__ == '__main__':
cli()
```