Code formatting
This commit is contained in:
parent
67d0f91a5b
commit
6b23f27e2f
|
@ -37,6 +37,7 @@ exit 0
|
||||||
Usage: doxy [OPTIONS] COMMAND [ARGS]...
|
Usage: doxy [OPTIONS] COMMAND [ARGS]...
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
|
-f, --format [fancy|simple] output formatting [default: fancy]
|
||||||
--help Show this message and exit.
|
--help Show this message and exit.
|
||||||
|
|
||||||
Commands:
|
Commands:
|
||||||
|
@ -58,6 +59,8 @@ Available Services
|
||||||
└── my-service-demo
|
└── my-service-demo
|
||||||
```
|
```
|
||||||
|
|
||||||
|
When `doxy -f simple` is used the output is easier to process by pipes.
|
||||||
|
|
||||||
### Start a service and detach
|
### Start a service and detach
|
||||||
```shell
|
```shell
|
||||||
$ doxy control other-service up -d
|
$ doxy control other-service up -d
|
||||||
|
|
42
doxy/cli.py
42
doxy/cli.py
|
@ -6,7 +6,7 @@ from rich import print
|
||||||
from rich.rule import Rule
|
from rich.rule import Rule
|
||||||
from rich.tree import Tree
|
from rich.tree import Tree
|
||||||
|
|
||||||
from doxy import services
|
from doxy import output, services
|
||||||
from doxy.config import Config
|
from doxy.config import Config
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -17,22 +17,6 @@ except FileNotFoundError as exc:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
@click.group()
|
|
||||||
@click.pass_context
|
|
||||||
def main(ctx):
|
|
||||||
ctx.ensure_object(dict)
|
|
||||||
ctx.obj["CONFIG"] = CONFIG
|
|
||||||
|
|
||||||
|
|
||||||
@click.command(help="list available services")
|
|
||||||
def list():
|
|
||||||
print(Rule(f"Listing services"))
|
|
||||||
tree = Tree("[bold]Available Services")
|
|
||||||
for service in services.find_services(Path(CONFIG.root_directory)):
|
|
||||||
tree.add(service)
|
|
||||||
print(tree)
|
|
||||||
|
|
||||||
|
|
||||||
def complete_service_name(ctx, param, incomplete):
|
def complete_service_name(ctx, param, incomplete):
|
||||||
return [
|
return [
|
||||||
k
|
k
|
||||||
|
@ -41,6 +25,28 @@ def complete_service_name(ctx, param, incomplete):
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@click.group()
|
||||||
|
@click.option(
|
||||||
|
"--format",
|
||||||
|
"-f",
|
||||||
|
type=click.Choice(["fancy", "simple"], case_sensitive=False),
|
||||||
|
default="fancy",
|
||||||
|
show_default=True,
|
||||||
|
help="output formatting",
|
||||||
|
)
|
||||||
|
@click.pass_context
|
||||||
|
def main(ctx, format):
|
||||||
|
ctx.ensure_object(dict)
|
||||||
|
ctx.obj["CONFIG"] = CONFIG
|
||||||
|
ctx.obj["FORMAT"] = format.lower()
|
||||||
|
|
||||||
|
|
||||||
|
@click.command(help="list available services")
|
||||||
|
@click.pass_context
|
||||||
|
def list(ctx):
|
||||||
|
output.print_services(ctx, services.find_services(Path(CONFIG.root_directory)))
|
||||||
|
|
||||||
|
|
||||||
@click.command(help="edit the compose file")
|
@click.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
|
||||||
|
@ -71,7 +77,7 @@ def control(ctx, service, command):
|
||||||
services.docker_compose_command(command, compose_file)
|
services.docker_compose_command(command, compose_file)
|
||||||
|
|
||||||
|
|
||||||
@click.command("update", help="pull the latest service images and restart")
|
@click.command(help="pull the latest service images and restart")
|
||||||
@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"
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
from click import Context, echo
|
||||||
|
from rich import print
|
||||||
|
from rich.rule import Rule
|
||||||
|
from rich.tree import Tree
|
||||||
|
|
||||||
|
|
||||||
|
def _print_services_fancy(services: List[str]):
|
||||||
|
print(Rule(f"Listing services"))
|
||||||
|
tree = Tree("[bold]Available Services")
|
||||||
|
for service in services:
|
||||||
|
tree.add(service)
|
||||||
|
print(tree)
|
||||||
|
|
||||||
|
|
||||||
|
def _print_services_simple(services: List[str]):
|
||||||
|
for service in services:
|
||||||
|
echo(service)
|
||||||
|
|
||||||
|
|
||||||
|
def print_services(ctx: Context, services: List[str]):
|
||||||
|
match ctx.obj["FORMAT"]:
|
||||||
|
case "fancy":
|
||||||
|
_print_services_fancy(services)
|
||||||
|
case "simple":
|
||||||
|
_print_services_simple(services)
|
||||||
|
case _:
|
||||||
|
echo("Unknown format choice")
|
Loading…
Reference in New Issue