Skip to content

Commit

Permalink
CLI: version -> --version (#43)
Browse files Browse the repository at this point in the history
* CLI: `version` -> `--version`

* Test the CLI
  • Loading branch information
dkmiller authored Jan 4, 2025
1 parent f28ee56 commit 52d2872
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
28 changes: 20 additions & 8 deletions ptah/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand All @@ -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():
"""
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "ptah-cli"
readme = "README.md"
version = "0.5.2"
version = "0.6.0"
authors = [
{ name = "Dan Miller", email = "[email protected]" }
]
Expand Down
12 changes: 12 additions & 0 deletions tests/cli/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import re

from click import BaseCommand
from typer.testing import CliRunner

from ptah.cli import app


def test_cli_click_object():
from ptah.cli import ptah

assert isinstance(ptah, BaseCommand)


def test_cli_version():
runner = CliRunner()
result = runner.invoke(app, ["--version"])
assert result.exit_code == 0
assert re.match(r"\d+\.\d+\.\d+", result.stdout)

0 comments on commit 52d2872

Please sign in to comment.