diff --git a/README.md b/README.md index 508f715..20f913a 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ ## About The Project -`compose-viz` is a compose file visualization tool that supports [compose-spec](https://github.com/compose-spec/compose-spec/blob/master/spec.md) and allows you to gernerate graph in [DOT](https://graphviz.org/doc/info/lang.html) format or `.png`. +`compose-viz` is a compose file visualization tool that supports [compose-spec](https://github.com/compose-spec/compose-spec/blob/master/spec.md) and allows you to gernerate graph in several formats. If you are looking for a compose file vizualization tool, and you are using one of the [compose-spec](https://github.com/compose-spec/compose-spec/blob/master/spec.md) implementations (e.g. [docker-compose](https://github.com/docker/compose)/[podman-compose](https://github.com/containers/podman-compose)), then `compose-viz` is a great choice for you. @@ -70,7 +70,7 @@ If you are looking for a compose file vizualization tool, and you are using one #### Graphviz -If you want to generate PNG (which is the default option), you need to install [Graphviz](https://graphviz.org/download/). +You need to install [Graphviz](https://graphviz.org/download/) to generate graphs. ### Installation @@ -93,9 +93,9 @@ cpv docker-compose.yml And this is what the result looks like: -![compose-viz.png](https://github.com/compose-viz/compose-viz/blob/main/examples/voting-app/compose-viz.png) +![compose-viz.svg](https://github.com/compose-viz/compose-viz/blob/main/examples/voting-app/compose-viz.svg) -Check out the result [here](https://github.com/compose-viz/compose-viz/blob/main/examples/voting-app/compose-viz.png). +Check out the result [here](https://github.com/compose-viz/compose-viz/blob/main/examples/voting-app). ### Usage @@ -103,12 +103,12 @@ Check out the result [here](https://github.com/compose-viz/compose-viz/blob/main ### Options -| Option | Description | -| ------------------------ | ------------------------------------------------------------------------------ | -| `-o, --output-path` | Output path for the generated visualization file. [default: ./compose-viz.png] | -| `-m, --format [PNG,DOT]` | Output format for the generated visualization file. [default: PNG] | -| `-v, --version` | Show the version of compose-viz. | -| `--help` | Show help and exit. | +| Option | Description | +| ------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `-o, --output-filename` | Output filename for the generated visualization file. [default: compose-viz] | +| `-m, --format` | Output format for the generated visualization file. See [supported formats](https://github.com/compose-viz/compose-viz/blob/main/compose_viz/viz_formats.py). [default: png] | +| `-v, --version` | Show the version of compose-viz. | +| `--help` | Show help and exit. |
diff --git a/compose_viz/__init__.py b/compose_viz/__init__.py index 467be58..606db7b 100644 --- a/compose_viz/__init__.py +++ b/compose_viz/__init__.py @@ -1,2 +1,2 @@ __app_name__ = "compose_viz" -__version__ = "0.1.1" +__version__ = "0.1.2" diff --git a/compose_viz/cli.py b/compose_viz/cli.py index e028d70..ffb10bd 100644 --- a/compose_viz/cli.py +++ b/compose_viz/cli.py @@ -1,4 +1,3 @@ -from enum import Enum from typing import Optional import typer @@ -6,12 +5,7 @@ import typer from compose_viz import __app_name__, __version__ from compose_viz.graph import Graph from compose_viz.parser import Parser - - -class VisualizationFormats(str, Enum): - png = "PNG" - dot = "DOT" - +from compose_viz.viz_formats import VizFormats app = typer.Typer( invoke_without_command=True, @@ -30,14 +24,14 @@ def _version_callback(value: bool) -> None: @app.callback() def compose_viz( input_path: str, - output_path: str = typer.Option( - "./compose-viz.png", - "--output-path", + output_filename: str = typer.Option( + "compose-viz", + "--output-filename", "-o", - help="Output path for the generated visualization file.", + help="Output filename for the generated visualization file.", ), - format: VisualizationFormats = typer.Option( - "PNG", + format: VizFormats = typer.Option( + "png", "--format", "-m", help="Output format for the generated visualization file.", @@ -57,7 +51,7 @@ def compose_viz( if compose: typer.echo(f"Successfully parsed {input_path}") - Graph(compose, output_path).render(format) + Graph(compose, output_filename).render(format) raise typer.Exit() diff --git a/compose_viz/graph.py b/compose_viz/graph.py index 57e34f5..32c5569 100644 --- a/compose_viz/graph.py +++ b/compose_viz/graph.py @@ -93,4 +93,4 @@ class Graph: for depends_on in service.depends_on: self.add_edge(service.name, depends_on, "depends_on") - self.dot.render(outfile=self.filename, format=format, cleanup=cleanup) + self.dot.render(outfile=f"{self.filename}.{format}", format=format, cleanup=cleanup) diff --git a/compose_viz/viz_formats.py b/compose_viz/viz_formats.py new file mode 100644 index 0000000..e81b832 --- /dev/null +++ b/compose_viz/viz_formats.py @@ -0,0 +1,45 @@ +from enum import Enum + + +class VizFormats(str, Enum): + png = "png" + dot = "dot" + jpeg = "jpeg" + json = "json" + svg = "svg" + + bmp = "bmp" + canon = "canon" + cmap = "cmap" + cmapx = "cmapx" + cmapx_np = "cmapx_np" + dot_json = "dot_json" + emf = "emf" + emfplus = "emfplus" + eps = "eps" + fig = "fig" + gif = "gif" + gv = "gv" + imap = "imap" + imap_np = "imap_np" + ismap = "ismap" + jpe = "jpe" + jpg = "jpg" + json0 = "json0" + metafile = "metafile" + mp = "mp" + pdf = "pdf" + pic = "pic" + plain = "plain" + plain_ext = "plain-ext" + pov = "pov" + ps = "ps" + ps2 = "ps2" + tif = "tif" + tiff = "tiff" + tk = "tk" + vml = "vml" + xdot = "xdot" + xdot1_2 = "xdot1.2" + xdot1_4 = "xdot1.4" + xdot_json = "xdot_json" diff --git a/examples/voting-app/compose-viz.svg b/examples/voting-app/compose-viz.svg new file mode 100644 index 0000000..f16a8ee --- /dev/null +++ b/examples/voting-app/compose-viz.svg @@ -0,0 +1,210 @@ + + + + + diff --git a/pyproject.toml b/pyproject.toml index 43a2b36..4ba3c53 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "compose-viz" -version = "0.1.1" -description = "A compose file visualization tool that supports compose-spec and allows you to gernerate graph in DOT format or PNG." +version = "0.1.2" +description = "A compose file visualization tool that supports compose-spec and allows you to gernerate graph in several formats." authors = ["Xyphuz Wu