click-with-aliasing


Nameclick-with-aliasing JSON
Version 1.1.1 PyPI version JSON
download
home_pageNone
SummaryA library that allows you to add aliases to your Click group and commands.
upload_time2025-07-21 20:36:50
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseMIT License Copyright (c) 2025 Marcus Fredriksson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords click alias group command
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Click With Aliasing

![top language](https://img.shields.io/github/languages/top/marcusfrdk/click-with-aliasing)
![code size](https://img.shields.io/github/languages/code-size/marcusfrdk/click-with-aliasing)
![last commit](https://img.shields.io/github/last-commit/marcusfrdk/click-with-aliasing)
![issues](https://img.shields.io/github/issues/marcusfrdk/click-with-aliasing)
![contributors](https://img.shields.io/github/contributors/marcusfrdk/click-with-aliasing)
![PyPI](https://img.shields.io/pypi/v/click-with-aliasing)
![License](https://img.shields.io/github/license/marcusfrdk/click-with-aliasing)
![Downloads](https://static.pepy.tech/badge/click-with-aliasing)
![Monthly Downloads](https://static.pepy.tech/badge/click-with-aliasing/month)

A powerful extension for [Click](https://click.palletsprojects.com/) that adds **command and group aliasing** support with **automatic async function handling**.

## Features

-   **Command Aliases**: Create multiple names for your commands
-   **Group Aliases**: Add aliases to command groups
-   **Automatic Async Support**: Seamlessly handle async functions without extra configuration
-   **Drop-in Replacement**: Works exactly like standard Click decorators
-   **Type Safe**: Full type hints support with proper IDE integration
-   **Help Integration**: Aliases automatically appear in help text

## Installation

```bash
pip install click-with-aliasing
```

**Requirements:** Python 3.10 or newer

## Quick Start

### Basic Command with Aliases

```python
from click_with_aliasing import command

@command(name="deploy", aliases=["d", "dep"])
def deploy():
    """Deploy the application"""
    print("Deploying application...")
```

Now you can run any of these:

```bash
my-cli deploy
my-cli d
my-cli dep
```

### Group with Aliases

```python
from click_with_aliasing import group, command

@group(name="database", aliases=["db"])
def database():
    """Database management commands"""
    pass

@command(name="migrate", aliases=["m"])
def migrate():
    """Run database migrations"""
    print("Running migrations...")

database.add_command(migrate)
```

Usage:

```bash
my-cli database migrate  # Full names
my-cli db m              # Using aliases
my-cli database m        # Mixed usage
```

## Async Support

The library automatically detects and handles async functions, meaning no extra configuration is needed.

### Async Commands

```python
import asyncio
from click_with_aliasing import command

@command(name="fetch", aliases=["f"])
async def fetch():
    """Fetch data asynchronously"""
    await asyncio.sleep(1)
    print("Data fetched!")
```

### Async Groups

```python
import asyncio
from click_with_aliasing import group, command

@group(name="api", aliases=["a"])
async def api_group():
    """API management commands"""
    await asyncio.sleep(0.1)  # Simulate async setup

@command(name="start", aliases=["s"])
async def start_server():
    """Start the API server"""
    print("Starting server...")

api_group.add_command(start_server)
```

## Complete Example

Here's a full CLI application demonstrating all features:

```python
import asyncio
import click
from click_with_aliasing import group, command

@group(name="myapp", aliases=["app"])
def cli():
    """My Application CLI"""
    pass

@group(name="database", aliases=["db"])
async def database():
    """Database management commands"""
    await asyncio.sleep(0.1)  # Simulate async setup

@command(name="migrate", aliases=["m", "mig"])
async def migrate():
    """Run database migrations"""
    print("Running migrations...")
    await asyncio.sleep(1)
    print("Migrations completed!")

@command(name="seed", aliases=["s"])
def seed():
    """Seed the database"""
    print("Seeding database...")

@command(name="start", aliases=["run", "serve"])
def start():
    """Start the application server"""
    print("Starting server on port 8000...")

@command(name="stop", aliases=["kill"])
def stop():
    """Stop the application server"""
    print("Stopping server...")

database.add_command(migrate)
database.add_command(seed)
cli.add_command(database)
cli.add_command(start)
cli.add_command(stop)

if __name__ == "__main__":
    cli()
```

Usage examples:

```bash
python myapp.py database migrate
python myapp.py db m
python myapp.py database mig

python myapp.py start
python myapp.py stop

python myapp.py --help
python myapp.py db --help
```

## API Reference

### `@command(name, *, aliases=None, **kwargs)`

Creates a command with optional aliases.

**Parameters:**

-   `name` (str): Primary command name
-   `aliases` (List[str], optional): List of alternative names
-   `**kwargs`: Additional arguments passed to `click.command()`

**Returns:** `AliasedCommand` instance

### `@group(name=None, *, aliases=None, **kwargs)`

Creates a command group with optional aliases.

**Parameters:**

-   `name` (str, optional): Group name (defaults to function name)
-   `aliases` (List[str], optional): List of alternative names
-   `**kwargs`: Additional arguments passed to `click.group()`

**Returns:** `AliasedGroup` instance

## Migration from Click

Migrating from standard Click is straightforward:

### Before (Standard Click)

```python
import click

@click.group()
def cli():
    pass

@click.command()
def deploy():
    pass
```

### After (Click with Aliasing)

```python
from click_with_aliasing import group, command

@group(aliases=["c"])
def cli():
    pass

@command(name="deploy", aliases=["d", "dep"])
def deploy():
    pass
```

## Help Text Integration

Aliases automatically appear in help text:

```txt
myapp database --help
Usage: myapp database [OPTIONS] COMMAND [ARGS]...

  Database management commands

Options:
  --help  Show this message and exit.

Commands:
  migrate (m, mig)  Run database migrations
  seed (s)          Seed the database
```

## Troubleshooting

### Common Issues

**Q: My async function isn't working**
A: The library automatically wraps async functions. Make sure you're using Python 3.10+ and have proper async/await syntax.

**Q: Aliases don't appear in help**
A: Ensure you're using the `AliasedGroup` class (automatic when using the `@group` decorator).

**Q: Type hints are not working**
A: Make sure you're importing from `click_with_aliasing` and have the latest version installed.

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Acknowledgments

Built on top of the great [Click](https://click.palletsprojects.com/) library by the Pallets team.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "click-with-aliasing",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "click, alias, group, command",
    "author": null,
    "author_email": "Marcus Fredriksson <marcus@marcusfredriksson.com>",
    "download_url": "https://files.pythonhosted.org/packages/eb/76/6398747dcfd47ba6de883b8510e895e7da8923af26489e73830fe0f15ae3/click_with_aliasing-1.1.1.tar.gz",
    "platform": null,
    "description": "# Click With Aliasing\n\n![top language](https://img.shields.io/github/languages/top/marcusfrdk/click-with-aliasing)\n![code size](https://img.shields.io/github/languages/code-size/marcusfrdk/click-with-aliasing)\n![last commit](https://img.shields.io/github/last-commit/marcusfrdk/click-with-aliasing)\n![issues](https://img.shields.io/github/issues/marcusfrdk/click-with-aliasing)\n![contributors](https://img.shields.io/github/contributors/marcusfrdk/click-with-aliasing)\n![PyPI](https://img.shields.io/pypi/v/click-with-aliasing)\n![License](https://img.shields.io/github/license/marcusfrdk/click-with-aliasing)\n![Downloads](https://static.pepy.tech/badge/click-with-aliasing)\n![Monthly Downloads](https://static.pepy.tech/badge/click-with-aliasing/month)\n\nA powerful extension for [Click](https://click.palletsprojects.com/) that adds **command and group aliasing** support with **automatic async function handling**.\n\n## Features\n\n-   **Command Aliases**: Create multiple names for your commands\n-   **Group Aliases**: Add aliases to command groups\n-   **Automatic Async Support**: Seamlessly handle async functions without extra configuration\n-   **Drop-in Replacement**: Works exactly like standard Click decorators\n-   **Type Safe**: Full type hints support with proper IDE integration\n-   **Help Integration**: Aliases automatically appear in help text\n\n## Installation\n\n```bash\npip install click-with-aliasing\n```\n\n**Requirements:** Python 3.10 or newer\n\n## Quick Start\n\n### Basic Command with Aliases\n\n```python\nfrom click_with_aliasing import command\n\n@command(name=\"deploy\", aliases=[\"d\", \"dep\"])\ndef deploy():\n    \"\"\"Deploy the application\"\"\"\n    print(\"Deploying application...\")\n```\n\nNow you can run any of these:\n\n```bash\nmy-cli deploy\nmy-cli d\nmy-cli dep\n```\n\n### Group with Aliases\n\n```python\nfrom click_with_aliasing import group, command\n\n@group(name=\"database\", aliases=[\"db\"])\ndef database():\n    \"\"\"Database management commands\"\"\"\n    pass\n\n@command(name=\"migrate\", aliases=[\"m\"])\ndef migrate():\n    \"\"\"Run database migrations\"\"\"\n    print(\"Running migrations...\")\n\ndatabase.add_command(migrate)\n```\n\nUsage:\n\n```bash\nmy-cli database migrate  # Full names\nmy-cli db m              # Using aliases\nmy-cli database m        # Mixed usage\n```\n\n## Async Support\n\nThe library automatically detects and handles async functions, meaning no extra configuration is needed.\n\n### Async Commands\n\n```python\nimport asyncio\nfrom click_with_aliasing import command\n\n@command(name=\"fetch\", aliases=[\"f\"])\nasync def fetch():\n    \"\"\"Fetch data asynchronously\"\"\"\n    await asyncio.sleep(1)\n    print(\"Data fetched!\")\n```\n\n### Async Groups\n\n```python\nimport asyncio\nfrom click_with_aliasing import group, command\n\n@group(name=\"api\", aliases=[\"a\"])\nasync def api_group():\n    \"\"\"API management commands\"\"\"\n    await asyncio.sleep(0.1)  # Simulate async setup\n\n@command(name=\"start\", aliases=[\"s\"])\nasync def start_server():\n    \"\"\"Start the API server\"\"\"\n    print(\"Starting server...\")\n\napi_group.add_command(start_server)\n```\n\n## Complete Example\n\nHere's a full CLI application demonstrating all features:\n\n```python\nimport asyncio\nimport click\nfrom click_with_aliasing import group, command\n\n@group(name=\"myapp\", aliases=[\"app\"])\ndef cli():\n    \"\"\"My Application CLI\"\"\"\n    pass\n\n@group(name=\"database\", aliases=[\"db\"])\nasync def database():\n    \"\"\"Database management commands\"\"\"\n    await asyncio.sleep(0.1)  # Simulate async setup\n\n@command(name=\"migrate\", aliases=[\"m\", \"mig\"])\nasync def migrate():\n    \"\"\"Run database migrations\"\"\"\n    print(\"Running migrations...\")\n    await asyncio.sleep(1)\n    print(\"Migrations completed!\")\n\n@command(name=\"seed\", aliases=[\"s\"])\ndef seed():\n    \"\"\"Seed the database\"\"\"\n    print(\"Seeding database...\")\n\n@command(name=\"start\", aliases=[\"run\", \"serve\"])\ndef start():\n    \"\"\"Start the application server\"\"\"\n    print(\"Starting server on port 8000...\")\n\n@command(name=\"stop\", aliases=[\"kill\"])\ndef stop():\n    \"\"\"Stop the application server\"\"\"\n    print(\"Stopping server...\")\n\ndatabase.add_command(migrate)\ndatabase.add_command(seed)\ncli.add_command(database)\ncli.add_command(start)\ncli.add_command(stop)\n\nif __name__ == \"__main__\":\n    cli()\n```\n\nUsage examples:\n\n```bash\npython myapp.py database migrate\npython myapp.py db m\npython myapp.py database mig\n\npython myapp.py start\npython myapp.py stop\n\npython myapp.py --help\npython myapp.py db --help\n```\n\n## API Reference\n\n### `@command(name, *, aliases=None, **kwargs)`\n\nCreates a command with optional aliases.\n\n**Parameters:**\n\n-   `name` (str): Primary command name\n-   `aliases` (List[str], optional): List of alternative names\n-   `**kwargs`: Additional arguments passed to `click.command()`\n\n**Returns:** `AliasedCommand` instance\n\n### `@group(name=None, *, aliases=None, **kwargs)`\n\nCreates a command group with optional aliases.\n\n**Parameters:**\n\n-   `name` (str, optional): Group name (defaults to function name)\n-   `aliases` (List[str], optional): List of alternative names\n-   `**kwargs`: Additional arguments passed to `click.group()`\n\n**Returns:** `AliasedGroup` instance\n\n## Migration from Click\n\nMigrating from standard Click is straightforward:\n\n### Before (Standard Click)\n\n```python\nimport click\n\n@click.group()\ndef cli():\n    pass\n\n@click.command()\ndef deploy():\n    pass\n```\n\n### After (Click with Aliasing)\n\n```python\nfrom click_with_aliasing import group, command\n\n@group(aliases=[\"c\"])\ndef cli():\n    pass\n\n@command(name=\"deploy\", aliases=[\"d\", \"dep\"])\ndef deploy():\n    pass\n```\n\n## Help Text Integration\n\nAliases automatically appear in help text:\n\n```txt\nmyapp database --help\nUsage: myapp database [OPTIONS] COMMAND [ARGS]...\n\n  Database management commands\n\nOptions:\n  --help  Show this message and exit.\n\nCommands:\n  migrate (m, mig)  Run database migrations\n  seed (s)          Seed the database\n```\n\n## Troubleshooting\n\n### Common Issues\n\n**Q: My async function isn't working**\nA: The library automatically wraps async functions. Make sure you're using Python 3.10+ and have proper async/await syntax.\n\n**Q: Aliases don't appear in help**\nA: Ensure you're using the `AliasedGroup` class (automatic when using the `@group` decorator).\n\n**Q: Type hints are not working**\nA: Make sure you're importing from `click_with_aliasing` and have the latest version installed.\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Acknowledgments\n\nBuilt on top of the great [Click](https://click.palletsprojects.com/) library by the Pallets team.\n",
    "bugtrack_url": null,
    "license": "MIT License\n        \n        Copyright (c) 2025 Marcus Fredriksson\n        \n        Permission is hereby granted, free of charge, to any person obtaining a copy\n        of this software and associated documentation files (the \"Software\"), to deal\n        in the Software without restriction, including without limitation the rights\n        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n        copies of the Software, and to permit persons to whom the Software is\n        furnished to do so, subject to the following conditions:\n        \n        The above copyright notice and this permission notice shall be included in all\n        copies or substantial portions of the Software.\n        \n        THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n        SOFTWARE.\n        ",
    "summary": "A library that allows you to add aliases to your Click group and commands.",
    "version": "1.1.1",
    "project_urls": {
        "Homepage": "https://github.com/marcusfrdk/click-with-aliasing",
        "Issues": "https://github.com/marcusfrdk/click-with-aliasing/issues",
        "Repository": "https://github.com/marcusfrdk/click-with-aliasing"
    },
    "split_keywords": [
        "click",
        " alias",
        " group",
        " command"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "2e48a16c795a877dec982dbbbbda948fa4b9d3be7d8d99956fd7c837620dc141",
                "md5": "23b11c0d8fbefe5831ffa9219b227af9",
                "sha256": "51a4571b0580ef4d533887f14c785ec1b068b54c4b4a05346ecab0a641e3493a"
            },
            "downloads": -1,
            "filename": "click_with_aliasing-1.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "23b11c0d8fbefe5831ffa9219b227af9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 8082,
            "upload_time": "2025-07-21T20:36:49",
            "upload_time_iso_8601": "2025-07-21T20:36:49.796572Z",
            "url": "https://files.pythonhosted.org/packages/2e/48/a16c795a877dec982dbbbbda948fa4b9d3be7d8d99956fd7c837620dc141/click_with_aliasing-1.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "eb766398747dcfd47ba6de883b8510e895e7da8923af26489e73830fe0f15ae3",
                "md5": "fb9d994ad7e9adf4aea4ea514e578f89",
                "sha256": "08e1d9151776f4883e786bbb4c79e3c40f035678a59be42caf331748304bfbfe"
            },
            "downloads": -1,
            "filename": "click_with_aliasing-1.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "fb9d994ad7e9adf4aea4ea514e578f89",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 8623,
            "upload_time": "2025-07-21T20:36:50",
            "upload_time_iso_8601": "2025-07-21T20:36:50.851105Z",
            "url": "https://files.pythonhosted.org/packages/eb/76/6398747dcfd47ba6de883b8510e895e7da8923af26489e73830fe0f15ae3/click_with_aliasing-1.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-21 20:36:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "marcusfrdk",
    "github_project": "click-with-aliasing",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "click-with-aliasing"
}
        
Elapsed time: 1.30442s