Output formatting for fancy printing

This commit is contained in:
jpk 2023-01-16 16:30:17 +01:00
parent 0ab7f1fd62
commit 766cb74974
2 changed files with 28 additions and 16 deletions

View File

@ -52,7 +52,7 @@ def list(ctx):
@click.pass_context
@services.only_if_service_exists
def edit(ctx, service):
print(Rule(f"Editing {service}"))
output.print_header(f"Editing {service}")
compose_file = services.get_compose_file(
Path(ctx.obj["CONFIG"].root_directory) / service
)
@ -70,7 +70,7 @@ def edit(ctx, service):
@click.pass_context
@services.only_if_service_exists
def control(ctx, service, command):
print(Rule(f"Controlling {service}"))
output.print_header(f"Controlling {service}")
compose_file = services.get_compose_file(
Path(ctx.obj["CONFIG"].root_directory) / service
)
@ -88,13 +88,13 @@ def update(ctx, service, remove):
compose_file = services.get_compose_file(
Path(ctx.obj["CONFIG"].root_directory) / service
)
print(Rule(f"Updating {service}"))
command_chain = [
["down" if remove else "stop"],
["pull"],
["up", "-d"],
]
for command in command_chain:
command_chain = {
f"Stopping {service}": ["down" if remove else "stop"],
f"Pulling {service} images": ["pull"],
f"Starting {service}": ["up", "-d"],
}
for title, command in command_chain.items():
output.print_header(ctx, title)
services.docker_compose_command(command, compose_file)
@ -106,12 +106,12 @@ def status(ctx, service):
compose_file = services.get_compose_file(
Path(ctx.obj["CONFIG"].root_directory) / service
)
print(Rule(f"Status of {service}"))
command_chain = [
["ps"],
["top"],
]
for command in command_chain:
command_chain = {
"Containers": ["ps"],
"Running processes": ["top"],
}
for title, command in command_chain.items():
output.print_header(ctx, title)
services.docker_compose_command(command, compose_file)

View File

@ -7,7 +7,7 @@ from rich.tree import Tree
def _print_services_fancy(services: List[str]):
print(Rule(f"Listing services"))
print(Rule("Listing services"))
tree = Tree("[bold]Available Services")
for service in services:
tree.add(service)
@ -27,3 +27,15 @@ def print_services(ctx: Context, services: List[str]):
_print_services_simple(services)
case _:
echo("Unknown format choice")
def _print_header_fancy(text: str):
print(Rule(text))
def print_header(ctx: Context, text: str):
match ctx.obj["FORMAT"]:
case "fancy":
_print_header_fancy(text)
case _:
pass