Added command aliases
This commit is contained in:
parent
468f1071e8
commit
ad2f52d885
21
doxy/cli.py
21
doxy/cli.py
|
@ -2,6 +2,7 @@ import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
from click_aliases import ClickAliasedGroup
|
||||||
|
|
||||||
from doxy import output
|
from doxy import output
|
||||||
from doxy.config import Config
|
from doxy.config import Config
|
||||||
|
@ -28,7 +29,7 @@ def complete_service_name(ctx, param, incomplete):
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@click.group()
|
@click.group(cls=ClickAliasedGroup)
|
||||||
@click.option(
|
@click.option(
|
||||||
"--format",
|
"--format",
|
||||||
"-f",
|
"-f",
|
||||||
|
@ -44,13 +45,13 @@ def main(ctx, format):
|
||||||
ctx.obj["FORMAT"] = format.lower()
|
ctx.obj["FORMAT"] = format.lower()
|
||||||
|
|
||||||
|
|
||||||
@click.command(help="list available services")
|
@main.command(help="list available services", aliases=["l", "ls"])
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def list(ctx):
|
def list(ctx):
|
||||||
output.print_services(ctx, find_services(Path(CONFIG.root_directory)))
|
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.argument("service", nargs=1, shell_complete=complete_service_name)
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
@only_if_service_exists
|
@only_if_service_exists
|
||||||
|
@ -60,11 +61,12 @@ def edit(ctx, service):
|
||||||
click.edit(filename=Path(compose_file))
|
click.edit(filename=Path(compose_file))
|
||||||
|
|
||||||
|
|
||||||
@click.command(
|
@main.command(
|
||||||
context_settings=dict(
|
context_settings=dict(
|
||||||
ignore_unknown_options=True,
|
ignore_unknown_options=True,
|
||||||
),
|
),
|
||||||
help="run docker-compose commands",
|
help="run docker-compose commands",
|
||||||
|
aliases=["c", "ctrl"],
|
||||||
)
|
)
|
||||||
@click.argument("service", nargs=1, shell_complete=complete_service_name)
|
@click.argument("service", nargs=1, shell_complete=complete_service_name)
|
||||||
@click.argument("command", nargs=-1)
|
@click.argument("command", nargs=-1)
|
||||||
|
@ -76,7 +78,9 @@ def control(ctx, service, command):
|
||||||
docker_compose_command(command, compose_file)
|
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.argument("service", nargs=1, shell_complete=complete_service_name)
|
||||||
@click.option(
|
@click.option(
|
||||||
"--remove", "-r", is_flag=True, default=False, help="remove unused volumes"
|
"--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)
|
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.argument("service", nargs=1, shell_complete=complete_service_name)
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
@only_if_service_exists
|
@only_if_service_exists
|
||||||
|
@ -108,8 +112,3 @@ def status(ctx, service):
|
||||||
for title, command in command_chain.items():
|
for title, command in command_chain.items():
|
||||||
output.print_header(ctx, title)
|
output.print_header(ctx, title)
|
||||||
docker_compose_command(command, compose_file)
|
docker_compose_command(command, compose_file)
|
||||||
|
|
||||||
|
|
||||||
availble_commands = (list, edit, control, update, status)
|
|
||||||
for command in availble_commands:
|
|
||||||
main.add_command(command)
|
|
||||||
|
|
|
@ -57,6 +57,20 @@ python-versions = ">=3.7"
|
||||||
[package.dependencies]
|
[package.dependencies]
|
||||||
colorama = {version = "*", markers = "platform_system == \"Windows\""}
|
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]]
|
[[package]]
|
||||||
name = "colorama"
|
name = "colorama"
|
||||||
version = "0.4.6"
|
version = "0.4.6"
|
||||||
|
@ -392,7 +406,7 @@ pyyaml = "*"
|
||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "1.1"
|
lock-version = "1.1"
|
||||||
python-versions = "^3.10"
|
python-versions = "^3.10"
|
||||||
content-hash = "698ee4791e8a998102d745734040bd0dab5ee606cf879c693327e0090f843e16"
|
content-hash = "4ed74e41dc0ada0fbb79ee4b58a75bb4007ba8a955f726711755cbd96cbe6445"
|
||||||
|
|
||||||
[metadata.files]
|
[metadata.files]
|
||||||
atomicwrites = []
|
atomicwrites = []
|
||||||
|
@ -407,6 +421,7 @@ click = [
|
||||||
{file = "click-8.1.3-py3-none-any.whl", hash = "sha256:bb4d8133cb15a609f44e8213d9b391b0809795062913b383c62be0ee95b1db48"},
|
{file = "click-8.1.3-py3-none-any.whl", hash = "sha256:bb4d8133cb15a609f44e8213d9b391b0809795062913b383c62be0ee95b1db48"},
|
||||||
{file = "click-8.1.3.tar.gz", hash = "sha256:7682dc8afb30297001674575ea00d1814d808d6a36af415a82bd481d37ba7b8e"},
|
{file = "click-8.1.3.tar.gz", hash = "sha256:7682dc8afb30297001674575ea00d1814d808d6a36af415a82bd481d37ba7b8e"},
|
||||||
]
|
]
|
||||||
|
click-aliases = []
|
||||||
colorama = []
|
colorama = []
|
||||||
commonmark = [
|
commonmark = [
|
||||||
{file = "commonmark-0.9.1-py2.py3-none-any.whl", hash = "sha256:da2f38c92590f83de410ba1a3cbceafbc74fee9def35f9251ba9a971d6d66fd9"},
|
{file = "commonmark-0.9.1-py2.py3-none-any.whl", hash = "sha256:da2f38c92590f83de410ba1a3cbceafbc74fee9def35f9251ba9a971d6d66fd9"},
|
||||||
|
|
|
@ -14,6 +14,7 @@ rich = "^13.0.1"
|
||||||
yamldataclassconfig = "^1.5.0"
|
yamldataclassconfig = "^1.5.0"
|
||||||
semver = "^2.13.0"
|
semver = "^2.13.0"
|
||||||
requests = "^2.28.2"
|
requests = "^2.28.2"
|
||||||
|
click-aliases = "^1.0.1"
|
||||||
|
|
||||||
[tool.poetry.scripts]
|
[tool.poetry.scripts]
|
||||||
doxy = "doxy.cli:main"
|
doxy = "doxy.cli:main"
|
||||||
|
|
Loading…
Reference in New Issue