Skip to content

Commit 52d2872

Browse files
authored
CLI: version -> --version (#43)
* CLI: `version` -> `--version` * Test the CLI
1 parent f28ee56 commit 52d2872

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

ptah/cli/__init__.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,26 @@
2424
app = typer.Typer(pretty_exceptions_enable=False)
2525

2626

27+
def version(value: bool):
28+
"""
29+
Current version of the Ptah CLI.
30+
"""
31+
if value:
32+
print(get(Version).version())
33+
raise typer.Exit()
34+
35+
36+
@app.callback()
37+
def common(
38+
ctx: typer.Context,
39+
version: bool = typer.Option(None, "--version", callback=version),
40+
):
41+
"""
42+
https://stackoverflow.com/a/71008105
43+
"""
44+
pass
45+
46+
2747
@app.command()
2848
def project(output: Serialization = Serialization.yaml):
2949
"""
@@ -39,14 +59,6 @@ def project(output: Serialization = Serialization.yaml):
3959
print(serialized)
4060

4161

42-
@app.command()
43-
def version():
44-
"""
45-
Current version of the Ptah CLI.
46-
"""
47-
print(get(Version).version())
48-
49-
5062
@app.command(name="build")
5163
def _build():
5264
"""

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "ptah-cli"
33
readme = "README.md"
4-
version = "0.5.2"
4+
version = "0.6.0"
55
authors = [
66
{ name = "Dan Miller", email = "[email protected]" }
77
]

tests/cli/test_cli.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1+
import re
2+
13
from click import BaseCommand
4+
from typer.testing import CliRunner
5+
6+
from ptah.cli import app
27

38

49
def test_cli_click_object():
510
from ptah.cli import ptah
611

712
assert isinstance(ptah, BaseCommand)
13+
14+
15+
def test_cli_version():
16+
runner = CliRunner()
17+
result = runner.invoke(app, ["--version"])
18+
assert result.exit_code == 0
19+
assert re.match(r"\d+\.\d+\.\d+", result.stdout)

0 commit comments

Comments
 (0)