Skip to content

Commit

Permalink
refactor(cli): use rich.console instead of rich.print (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
afuetterer authored Jun 3, 2024
1 parent 4400ca0 commit 943b1a9
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/re3data/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import sys
import typing

from rich import print
from rich.console import Console

import re3data
from re3data._client import ReturnType
Expand All @@ -21,6 +21,8 @@
logger.error("`typer` is missing. Please run 'pip install python-re3data[cli]' to use the CLI.")
sys.exit(1)

console = Console()

CONTEXT_SETTINGS = {"help_option_names": ["-h", "--help"]}

app = typer.Typer(no_args_is_help=True, context_settings=CONTEXT_SETTINGS)
Expand All @@ -33,8 +35,8 @@ def _version_callback(show_version: bool) -> None:
from re3data import __version__

if show_version:
typer.echo(f"{__version__}")
raise typer.Exit
console.print(__version__)
raise typer.Exit(code=0)


@app.callback(context_settings=CONTEXT_SETTINGS)
Expand All @@ -57,11 +59,11 @@ def callback(
def list_repositories(return_type: ReturnType = ReturnType.xml) -> None:
"""List the metadata of all repositories in the re3data API."""
response = re3data.repositories.list(return_type=return_type.value)
print(response)
console.print(response)


@repositories_app.command("get")
def get_repository(repository_id: str, return_type: ReturnType = ReturnType.xml) -> None:
"""Get the metadata of a specific repository."""
response = re3data.repositories.get(repository_id, return_type=return_type.value)
print(response)
console.print(response)

0 comments on commit 943b1a9

Please sign in to comment.