From 92b442dc6010ca61550f449e2ecfb76deaf43c65 Mon Sep 17 00:00:00 2001 From: Dan Miller Date: Sat, 4 Jan 2025 11:25:21 -0800 Subject: [PATCH] CLI: `version` -> `--version` --- ptah/cli/__init__.py | 28 ++++++++++++++++++++-------- pyproject.toml | 2 +- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/ptah/cli/__init__.py b/ptah/cli/__init__.py index ff7f9ef..e815de8 100644 --- a/ptah/cli/__init__.py +++ b/ptah/cli/__init__.py @@ -24,6 +24,26 @@ app = typer.Typer(pretty_exceptions_enable=False) +def version(value: bool): + """ + Current version of the Ptah CLI. + """ + if value: + print(get(Version).version()) + raise typer.Exit() + + +@app.callback() +def common( + ctx: typer.Context, + version: bool = typer.Option(None, "--version", callback=version), +): + """ + https://stackoverflow.com/a/71008105 + """ + pass + + @app.command() def project(output: Serialization = Serialization.yaml): """ @@ -39,14 +59,6 @@ def project(output: Serialization = Serialization.yaml): print(serialized) -@app.command() -def version(): - """ - Current version of the Ptah CLI. - """ - print(get(Version).version()) - - @app.command(name="build") def _build(): """ diff --git a/pyproject.toml b/pyproject.toml index 792913e..ff4e5f1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "ptah-cli" readme = "README.md" -version = "0.5.2" +version = "0.6.0" authors = [ { name = "Dan Miller", email = "daniel.keegan.miller@gmail.com" } ]