doxy/doxy/output.py

56 lines
1.5 KiB
Python
Raw Permalink Normal View History

2023-01-16 14:42:00 +01:00
from typing import List
from click import Context, echo
from rich import print
from rich.rule import Rule
from rich.tree import Tree
2023-12-03 16:43:30 +01:00
def _print_services_fancy(services: List, status: str):
2023-01-16 16:30:17 +01:00
print(Rule("Listing services"))
2023-12-03 16:43:30 +01:00
tree = Tree(f"[bold]{status.capitalize()} Services")
2023-01-16 14:42:00 +01:00
for service in services:
if isinstance(service, tuple):
compose, subservices = service
node = tree.add(compose)
for subservice in subservices:
node.add(subservice)
else:
tree.add(service)
2023-01-16 14:42:00 +01:00
print(tree)
2023-12-03 16:43:30 +01:00
def _print_services_simple(services: List[str], status: str):
2023-01-16 14:42:00 +01:00
for service in services:
if isinstance(service, tuple):
compose, subservices = service
2023-12-03 16:43:30 +01:00
echo(f"{compose}\t{','.join(subservices)} ({status})")
else:
echo(service)
2023-01-16 14:42:00 +01:00
2023-12-03 16:43:30 +01:00
def print_services(ctx: Context, services: List[str], disabled_services=False):
if not disabled_services:
status = "enabled"
else:
status = "disabled"
2023-01-16 14:42:00 +01:00
match ctx.obj["FORMAT"]:
case "fancy":
2023-12-03 16:43:30 +01:00
_print_services_fancy(services, status)
2023-01-16 14:42:00 +01:00
case "simple":
2023-12-03 16:43:30 +01:00
_print_services_simple(services, status)
2023-01-16 14:42:00 +01:00
case _:
echo("Unknown format choice")
2023-01-16 16:30:17 +01:00
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