Skip to content

Commit

Permalink
feat(cli): Add list command to display all available components
Browse files Browse the repository at this point in the history
Closes #36
  • Loading branch information
alexpovel committed Jul 29, 2022
1 parent 59033ae commit eaaa00c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
30 changes: 30 additions & 0 deletions ancv/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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(
Expand Down
5 changes: 5 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eaaa00c

Please sign in to comment.