From eaaa00ca89ffb22da79d9e9b49520e2953550389 Mon Sep 17 00:00:00 2001 From: Alex Povel Date: Fri, 29 Jul 2022 20:13:32 +0200 Subject: [PATCH] feat(cli): Add `list` command to display all available components Closes #36 --- ancv/__main__.py | 30 ++++++++++++++++++++++++++++++ tests/test_main.py | 5 +++++ 2 files changed, 35 insertions(+) diff --git a/ancv/__main__.py b/ancv/__main__.py index f4fd044..274c8bf 100644 --- a/ancv/__main__.py +++ b/ancv/__main__.py @@ -12,11 +12,15 @@ import structlog import typer from pydantic import ValidationError +from rich import print as rprint +from rich.tree import Tree from structlog.processors import JSONRenderer, TimeStamper, add_log_level from ancv.exceptions import ResumeConfigError from ancv.reflection import METADATA from ancv.visualization.templates import Template +from ancv.visualization.themes import THEMES +from ancv.visualization.translations import TRANSLATIONS from ancv.web.server import APIHandler, FileHandler, ServerContext app = typer.Typer(no_args_is_help=True, help=__doc__) @@ -94,6 +98,32 @@ def version() -> None: print(f"ancv {METADATA.version}") +@app.command() +def list() -> None: + """Lists all available components (templates, themes and translations).""" + + # This is pretty raw, but it works. Could make it prettier using more of `rich`. + + tree = Tree("Components") + + template_tree = Tree("Templates") + for template in Template.subclasses().keys(): + template_tree.add(template) + tree.add(template_tree) + + theme_tree = Tree("Themes") + for theme in THEMES: + theme_tree.add(theme) + tree.add(theme_tree) + + translation_tree = Tree("Translations") + for translation in TRANSLATIONS: + translation_tree.add(translation) + tree.add(translation_tree) + + rprint(tree) + + @app.callback() def main( verbose: bool = typer.Option( diff --git a/tests/test_main.py b/tests/test_main.py index cc05041..f63c157 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -32,6 +32,11 @@ def test_version_exists(): assert result.exit_code == 0 +def test_list_exists(): + result = RUNNER.invoke(app, ["list"]) + assert result.exit_code == 0 + + @pytest.mark.parametrize("filename", RESUMES) # All resumes as a single fixture wouldn't be too bad either but doesn't work: # https://stackoverflow.com/q/56672179/11477374