2022-05-07 18:42:14 +02:00
|
|
|
from typing import Optional
|
2022-05-18 17:28:18 +02:00
|
|
|
|
|
|
|
import typer
|
|
|
|
|
2022-05-07 18:42:14 +02:00
|
|
|
from compose_viz import __app_name__, __version__
|
2022-05-16 18:57:14 +02:00
|
|
|
from compose_viz.graph import Graph
|
2022-05-27 08:17:04 +02:00
|
|
|
from compose_viz.models.viz_formats import VizFormats
|
2022-05-18 17:28:18 +02:00
|
|
|
from compose_viz.parser import Parser
|
2022-05-07 18:42:14 +02:00
|
|
|
|
|
|
|
app = typer.Typer(
|
|
|
|
invoke_without_command=True,
|
|
|
|
no_args_is_help=True,
|
|
|
|
subcommand_metavar="",
|
|
|
|
add_completion=False,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def _version_callback(value: bool) -> None:
|
|
|
|
if value:
|
|
|
|
typer.echo(f"{__app_name__} {__version__}")
|
|
|
|
raise typer.Exit()
|
|
|
|
|
|
|
|
|
|
|
|
@app.callback()
|
|
|
|
def compose_viz(
|
|
|
|
input_path: str,
|
2022-05-26 05:06:06 +02:00
|
|
|
output_filename: str = typer.Option(
|
|
|
|
"compose-viz",
|
|
|
|
"--output-filename",
|
2022-05-07 18:42:14 +02:00
|
|
|
"-o",
|
2022-05-26 05:06:06 +02:00
|
|
|
help="Output filename for the generated visualization file.",
|
2022-05-07 18:42:14 +02:00
|
|
|
),
|
2022-05-26 05:06:06 +02:00
|
|
|
format: VizFormats = typer.Option(
|
|
|
|
"png",
|
2022-05-07 18:42:14 +02:00
|
|
|
"--format",
|
|
|
|
"-m",
|
2022-05-15 13:18:10 +02:00
|
|
|
help="Output format for the generated visualization file.",
|
2022-05-07 18:42:14 +02:00
|
|
|
),
|
2022-12-15 11:45:49 +01:00
|
|
|
root_service: str = typer.Option(
|
|
|
|
None,
|
|
|
|
"--root-service",
|
|
|
|
"-r",
|
|
|
|
help="Root of the service tree (convenient for large compose yamls)",
|
|
|
|
),
|
2024-04-27 18:42:34 +02:00
|
|
|
include_legend: bool = typer.Option(
|
|
|
|
False,
|
|
|
|
"--legend",
|
|
|
|
"-l",
|
|
|
|
help="Include a legend in the visualization.",
|
|
|
|
),
|
2022-05-07 18:42:14 +02:00
|
|
|
_: Optional[bool] = typer.Option(
|
|
|
|
None,
|
|
|
|
"--version",
|
|
|
|
"-v",
|
2022-05-15 13:18:10 +02:00
|
|
|
help="Show the version of compose-viz.",
|
2022-05-07 18:42:14 +02:00
|
|
|
callback=_version_callback,
|
|
|
|
is_eager=True,
|
2022-05-18 17:28:18 +02:00
|
|
|
),
|
2022-05-07 18:42:14 +02:00
|
|
|
) -> None:
|
|
|
|
parser = Parser()
|
2022-12-15 11:45:49 +01:00
|
|
|
compose = parser.parse(input_path, root_service=root_service)
|
2022-05-07 18:42:14 +02:00
|
|
|
|
|
|
|
if compose:
|
|
|
|
typer.echo(f"Successfully parsed {input_path}")
|
|
|
|
|
2024-04-27 18:42:34 +02:00
|
|
|
Graph(compose, output_filename, include_legend).render(format)
|
2022-05-16 18:57:14 +02:00
|
|
|
|
2022-05-07 18:42:14 +02:00
|
|
|
raise typer.Exit()
|
2022-05-08 17:03:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
def start_cli() -> None:
|
2022-05-15 13:18:10 +02:00
|
|
|
app(prog_name="cpv")
|