click-with-aliasing


Nameclick-with-aliasing JSON
Version 1.2.0 PyPI version JSON
download
home_pageNone
SummaryA library that allows you to add aliases to your Click group and commands.
upload_time2025-10-24 16:31:54
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** and **advanced parameter validation**.

## Features

- **Command Aliases**: Create multiple names for your commands
- **Group Aliases**: Add aliases to command groups
- **Enhanced Options & Arguments**: Mutual exclusivity, requirements, and group constraints
- **Validation Rules**: Group-level validation with multiple modes (all_or_none, at_least, at_most, exactly)
- **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

## Documentation

- **[Command](docs/COMMAND.md)** - Command decorator with aliasing support
- **[Group](docs/GROUP.md)** - Group decorator for organizing commands
- **[Option](docs/OPTION.md)** - Enhanced options with mutual exclusivity and requirements
- **[Argument](docs/ARGUMENT.md)** - Enhanced arguments with validation constraints
- **[Rule](docs/RULE.md)** - Group-level validation rules for complex parameter logic

## 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
```

### Enhanced Options with Validation

```python
from click_with_aliasing import command, option

@command(name="auth")
@option("--username", requires=["password"], mutually_exclusive=["token"])
@option("--password", requires=["username"], mutually_exclusive=["token"])
@option("--token", mutually_exclusive=["username", "password"])
def auth(username, password, token):
    """Authenticate with username/password or token"""
    if token:
        print("Authenticating with token")
    elif username and password:
        print(f"Authenticating as {username}")
```

Usage:

```bash
my-cli auth --token abc123                          # Valid
my-cli auth --username admin --password secret      # Valid
my-cli auth --username admin                        # Error: requires password
my-cli auth --token abc123 --username admin         # Error: mutually exclusive
```

### Validation Rules

```python
from click_with_aliasing import command, option, rule

@command(name="deploy")
@option("--production", is_flag=True)
@option("--staging", is_flag=True)
@option("--development", is_flag=True)
@rule(["production", "staging", "development"], mode="exactly", count=1)
def deploy(production, staging, development):
    """Deploy to exactly one environment"""
    env = "production" if production else "staging" if staging else "development"
    print(f"Deploying to {env}")
```

Usage:

```bash
my-cli deploy --production                          # Valid
my-cli deploy --staging                             # Valid
my-cli deploy --production --staging                # Error: exactly 1 required
my-cli deploy                                        # Error: exactly 1 required
```

## 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)
```

## Key Concepts

### Command & Group Aliases

Add multiple names to commands and groups for convenience:

```python
@command(name="deploy", aliases=["d", "dep"])
@group(name="database", aliases=["db", "d"])
```

### Option Validation

**Mutual Exclusivity**: Only one option from a set can be used

```python
@option("--json", mutually_exclusive=["xml", "yaml"])
```

**Requirements**: Options that must be used together

```python
@option("--username", requires=["password"])
```

**Group Constraints**: Organize options and apply constraints collectively

```python
@option("--json", group="format", group_mutually_exclusive=["output"])
```

### Validation Rules

Apply group-level validation with different modes:

- **all_or_none**: All parameters or none
- **at_least**: Minimum number required
- **at_most**: Maximum number allowed
- **exactly**: Exact number required

```python
@rule(["host", "port", "database"], mode="all_or_none")
@rule(["email", "sms", "slack"], mode="at_least", count=1)
@rule(["json", "xml", "yaml"], mode="at_most", count=1)
@rule(["file1", "file2", "file3"], mode="exactly", count=2)
```

## Migration from Click

Migrating from standard Click is straightforward - just change your imports:

### Before (Standard Click)

```python
import click

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

@click.command()
@click.option("--name", default="World")
@click.argument("file")
def greet(name, file):
    pass
```

### After (Click with Aliasing)

```python
from click_with_aliasing import group, command, option, argument

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

@command(name="greet", aliases=["g"])
@option("--name", default="World", mutually_exclusive=["file"])
@argument("file", required=False, mutually_exclusive=["name"])
def greet(name, file):
    pass
```

All standard Click features work exactly the same, with optional enhancements available.

## 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
```

## Contributing

Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details on our development process, coding standards, and how to submit pull requests.

## 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/e6/5c/bda5c9e78b76255a7a175077969c169874855aa62273e9cbaa2bd0cec137/click_with_aliasing-1.2.0.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** and **advanced parameter validation**.\n\n## Features\n\n- **Command Aliases**: Create multiple names for your commands\n- **Group Aliases**: Add aliases to command groups\n- **Enhanced Options & Arguments**: Mutual exclusivity, requirements, and group constraints\n- **Validation Rules**: Group-level validation with multiple modes (all_or_none, at_least, at_most, exactly)\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## Documentation\n\n- **[Command](docs/COMMAND.md)** - Command decorator with aliasing support\n- **[Group](docs/GROUP.md)** - Group decorator for organizing commands\n- **[Option](docs/OPTION.md)** - Enhanced options with mutual exclusivity and requirements\n- **[Argument](docs/ARGUMENT.md)** - Enhanced arguments with validation constraints\n- **[Rule](docs/RULE.md)** - Group-level validation rules for complex parameter logic\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### Enhanced Options with Validation\n\n```python\nfrom click_with_aliasing import command, option\n\n@command(name=\"auth\")\n@option(\"--username\", requires=[\"password\"], mutually_exclusive=[\"token\"])\n@option(\"--password\", requires=[\"username\"], mutually_exclusive=[\"token\"])\n@option(\"--token\", mutually_exclusive=[\"username\", \"password\"])\ndef auth(username, password, token):\n    \"\"\"Authenticate with username/password or token\"\"\"\n    if token:\n        print(\"Authenticating with token\")\n    elif username and password:\n        print(f\"Authenticating as {username}\")\n```\n\nUsage:\n\n```bash\nmy-cli auth --token abc123                          # Valid\nmy-cli auth --username admin --password secret      # Valid\nmy-cli auth --username admin                        # Error: requires password\nmy-cli auth --token abc123 --username admin         # Error: mutually exclusive\n```\n\n### Validation Rules\n\n```python\nfrom click_with_aliasing import command, option, rule\n\n@command(name=\"deploy\")\n@option(\"--production\", is_flag=True)\n@option(\"--staging\", is_flag=True)\n@option(\"--development\", is_flag=True)\n@rule([\"production\", \"staging\", \"development\"], mode=\"exactly\", count=1)\ndef deploy(production, staging, development):\n    \"\"\"Deploy to exactly one environment\"\"\"\n    env = \"production\" if production else \"staging\" if staging else \"development\"\n    print(f\"Deploying to {env}\")\n```\n\nUsage:\n\n```bash\nmy-cli deploy --production                          # Valid\nmy-cli deploy --staging                             # Valid\nmy-cli deploy --production --staging                # Error: exactly 1 required\nmy-cli deploy                                        # Error: exactly 1 required\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## Key Concepts\n\n### Command & Group Aliases\n\nAdd multiple names to commands and groups for convenience:\n\n```python\n@command(name=\"deploy\", aliases=[\"d\", \"dep\"])\n@group(name=\"database\", aliases=[\"db\", \"d\"])\n```\n\n### Option Validation\n\n**Mutual Exclusivity**: Only one option from a set can be used\n\n```python\n@option(\"--json\", mutually_exclusive=[\"xml\", \"yaml\"])\n```\n\n**Requirements**: Options that must be used together\n\n```python\n@option(\"--username\", requires=[\"password\"])\n```\n\n**Group Constraints**: Organize options and apply constraints collectively\n\n```python\n@option(\"--json\", group=\"format\", group_mutually_exclusive=[\"output\"])\n```\n\n### Validation Rules\n\nApply group-level validation with different modes:\n\n- **all_or_none**: All parameters or none\n- **at_least**: Minimum number required\n- **at_most**: Maximum number allowed\n- **exactly**: Exact number required\n\n```python\n@rule([\"host\", \"port\", \"database\"], mode=\"all_or_none\")\n@rule([\"email\", \"sms\", \"slack\"], mode=\"at_least\", count=1)\n@rule([\"json\", \"xml\", \"yaml\"], mode=\"at_most\", count=1)\n@rule([\"file1\", \"file2\", \"file3\"], mode=\"exactly\", count=2)\n```\n\n## Migration from Click\n\nMigrating from standard Click is straightforward - just change your imports:\n\n### Before (Standard Click)\n\n```python\nimport click\n\n@click.group()\ndef cli():\n    pass\n\n@click.command()\n@click.option(\"--name\", default=\"World\")\n@click.argument(\"file\")\ndef greet(name, file):\n    pass\n```\n\n### After (Click with Aliasing)\n\n```python\nfrom click_with_aliasing import group, command, option, argument\n\n@group(aliases=[\"c\"])\ndef cli():\n    pass\n\n@command(name=\"greet\", aliases=[\"g\"])\n@option(\"--name\", default=\"World\", mutually_exclusive=[\"file\"])\n@argument(\"file\", required=False, mutually_exclusive=[\"name\"])\ndef greet(name, file):\n    pass\n```\n\nAll standard Click features work exactly the same, with optional enhancements available.\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## Contributing\n\nContributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details on our development process, coding standards, and how to submit pull requests.\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.2.0",
    "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": "b55c984b0b8233e5292e70a4ad4b1ac54f59d9c6ed03940d8c29c1e9516a8cd5",
                "md5": "6991d822bc3edf26f5c315a2b8a6d122",
                "sha256": "8b902d167b5806d9ee3b9ccbb9646789ab8867b346e0b5b44fcf3a1366537f5d"
            },
            "downloads": -1,
            "filename": "click_with_aliasing-1.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6991d822bc3edf26f5c315a2b8a6d122",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 16524,
            "upload_time": "2025-10-24T16:31:53",
            "upload_time_iso_8601": "2025-10-24T16:31:53.337604Z",
            "url": "https://files.pythonhosted.org/packages/b5/5c/984b0b8233e5292e70a4ad4b1ac54f59d9c6ed03940d8c29c1e9516a8cd5/click_with_aliasing-1.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "e65cbda5c9e78b76255a7a175077969c169874855aa62273e9cbaa2bd0cec137",
                "md5": "c394e0ddfc3c93d1449f8e683b2ca671",
                "sha256": "97778b54b182e05b08e89bd7e359a22017d222e8abd8db3af7df389ffda393f8"
            },
            "downloads": -1,
            "filename": "click_with_aliasing-1.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "c394e0ddfc3c93d1449f8e683b2ca671",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 20797,
            "upload_time": "2025-10-24T16:31:54",
            "upload_time_iso_8601": "2025-10-24T16:31:54.307640Z",
            "url": "https://files.pythonhosted.org/packages/e6/5c/bda5c9e78b76255a7a175077969c169874855aa62273e9cbaa2bd0cec137/click_with_aliasing-1.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-24 16:31:54",
    "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: 2.65892s