compose-viz/compose_viz/cli.py

61 lines
1.3 KiB
Python
Raw Normal View History

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
),
_: 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()
compose = parser.parse(input_path)
if compose:
typer.echo(f"Successfully parsed {input_path}")
2022-05-26 05:06:06 +02:00
Graph(compose, output_filename).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")