Click Aliases
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.
Warnings
- gotcha Click's native functionality supports command prefix matching (e.g., 'comm' for 'commit' if unique), but not 'true' distinct aliases. `click-aliases` provides the latter. Be aware of this distinction to avoid confusion about which form of aliasing you need.
- gotcha When combining `click-aliases` with other Click extensions (e.g., `rich-click`), there might be conflicts or unexpected behavior, particularly regarding help text formatting. Aliases may not appear correctly or may break the formatting of individual command help.
- deprecated Click's core maintainers have previously indicated that alias functionality is covered by overridable APIs and is not planned for direct integration into Click's core. While `click-aliases` provides a convenient abstraction, users should be aware that native support for this specific aliasing pattern is unlikely to be added to Click itself.
Install
-
pip install click-aliases
Imports
- ClickAliasedGroup
from click_aliases import ClickAliasedGroup
Quickstart
import click
from click_aliases import ClickAliasedGroup
@click.group(cls=ClickAliasedGroup)
def cli():
"""A simple CLI with aliases."""
pass
@cli.command(aliases=['create', 'mk'])
def make():
"""Makes something new."""
click.echo('Making something...')
@cli.command(aliases=['rm', 'delete'])
def remove():
"""Removes something."""
click.echo('Removing something...')
if __name__ == '__main__':
cli()