diff --git a/doxy/cli.py b/doxy/cli.py index b612d27..9826e4e 100644 --- a/doxy/cli.py +++ b/doxy/cli.py @@ -2,6 +2,7 @@ import sys from pathlib import Path import click +from click_aliases import ClickAliasedGroup from doxy import output from doxy.config import Config @@ -28,7 +29,7 @@ def complete_service_name(ctx, param, incomplete): ] -@click.group() +@click.group(cls=ClickAliasedGroup) @click.option( "--format", "-f", @@ -44,13 +45,13 @@ def main(ctx, format): ctx.obj["FORMAT"] = format.lower() -@click.command(help="list available services") +@main.command(help="list available services", aliases=["l", "ls"]) @click.pass_context def list(ctx): output.print_services(ctx, find_services(Path(CONFIG.root_directory))) -@click.command(help="edit the compose file") +@main.command(help="edit the compose file") @click.argument("service", nargs=1, shell_complete=complete_service_name) @click.pass_context @only_if_service_exists @@ -60,11 +61,12 @@ def edit(ctx, service): click.edit(filename=Path(compose_file)) -@click.command( +@main.command( context_settings=dict( ignore_unknown_options=True, ), help="run docker-compose commands", + aliases=["c", "ctrl"], ) @click.argument("service", nargs=1, shell_complete=complete_service_name) @click.argument("command", nargs=-1) @@ -76,7 +78,9 @@ def control(ctx, service, command): docker_compose_command(command, compose_file) -@click.command(help="pull the latest service images and restart") +@main.command( + help="pull the latest service images and restart", aliases=["upd", "sync"] +) @click.argument("service", nargs=1, shell_complete=complete_service_name) @click.option( "--remove", "-r", is_flag=True, default=False, help="remove unused volumes" @@ -95,7 +99,7 @@ def update(ctx, service, remove): docker_compose_command(command, compose_file) -@click.command(help="show service status (ps, top)") +@main.command(help="show service status (ps, top)", aliases=["stat", "info"]) @click.argument("service", nargs=1, shell_complete=complete_service_name) @click.pass_context @only_if_service_exists @@ -108,8 +112,3 @@ def status(ctx, service): for title, command in command_chain.items(): output.print_header(ctx, title) docker_compose_command(command, compose_file) - - -availble_commands = (list, edit, control, update, status) -for command in availble_commands: - main.add_command(command) diff --git a/poetry.lock b/poetry.lock index c8f6b5a..baeb868 100644 --- a/poetry.lock +++ b/poetry.lock @@ -57,6 +57,20 @@ python-versions = ">=3.7" [package.dependencies] colorama = {version = "*", markers = "platform_system == \"Windows\""} +[[package]] +name = "click-aliases" +version = "1.0.1" +description = "Enable aliases for Click" +category = "main" +optional = false +python-versions = "*" + +[package.dependencies] +click = "*" + +[package.extras] +dev = ["flake8", "flake8-import-order", "tox-travis", "pytest", "pytest-cov", "coveralls", "wheel"] + [[package]] name = "colorama" version = "0.4.6" @@ -392,7 +406,7 @@ pyyaml = "*" [metadata] lock-version = "1.1" python-versions = "^3.10" -content-hash = "698ee4791e8a998102d745734040bd0dab5ee606cf879c693327e0090f843e16" +content-hash = "4ed74e41dc0ada0fbb79ee4b58a75bb4007ba8a955f726711755cbd96cbe6445" [metadata.files] atomicwrites = [] @@ -407,6 +421,7 @@ click = [ {file = "click-8.1.3-py3-none-any.whl", hash = "sha256:bb4d8133cb15a609f44e8213d9b391b0809795062913b383c62be0ee95b1db48"}, {file = "click-8.1.3.tar.gz", hash = "sha256:7682dc8afb30297001674575ea00d1814d808d6a36af415a82bd481d37ba7b8e"}, ] +click-aliases = [] colorama = [] commonmark = [ {file = "commonmark-0.9.1-py2.py3-none-any.whl", hash = "sha256:da2f38c92590f83de410ba1a3cbceafbc74fee9def35f9251ba9a971d6d66fd9"}, diff --git a/pyproject.toml b/pyproject.toml index 00fea8c..c24828c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,6 +14,7 @@ rich = "^13.0.1" yamldataclassconfig = "^1.5.0" semver = "^2.13.0" requests = "^2.28.2" +click-aliases = "^1.0.1" [tool.poetry.scripts] doxy = "doxy.cli:main"