FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat(cli): add --version flag (#26) · pythonnative/pythonnative@5ceb010 · GitHub

Repository navigation

Commit 5ceb010

Browse files
authored
feat(cli): add --version flag (#26)
Refs: #20
1 parent b57586f commit 5ceb010

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

‎src/pythonnative/cli/pn.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import subprocess
3535
import sys
3636
import time
37+
from importlib.metadata import version as pkg_version
3738
from pathlib import Path
3839
from typing import Any, Dict, List, Optional
3940

@@ -863,6 +864,12 @@ def on_change(changed_files: List[str]) -> None:
863864

864865
def _build_parser() -> argparse.ArgumentParser:
865866
parser = argparse.ArgumentParser(prog="pn", description="PythonNative CLI")
867+
parser.add_argument(
868+
"--version",
869+
"-V",
870+
action="version",
871+
version=f"pn {pkg_version('pythonnative')}",
872+
)
866873
subparsers = parser.add_subparsers()
867874

868875
parser_init = subparsers.add_parser("init", help="Scaffold a new project")

‎tests/test_cli.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@ def run_pn(args: List[str], cwd: str) -> "subprocess.CompletedProcess[str]":
1717
return subprocess.run(cmd, cwd=cwd, check=False, capture_output=True, text=True)
1818

1919

20+
def test_cli_version(tmp_path: Path) -> None:
21+
result = run_pn(["--version"], str(tmp_path))
22+
23+
assert result.returncode == 0
24+
assert result.stdout.strip().startswith("pn ")
25+
26+
27+
def test_cli_short_version_flag(tmp_path: Path) -> None:
28+
result = run_pn(["-V"], str(tmp_path))
29+
30+
assert result.returncode == 0
31+
assert result.stdout.strip().startswith("pn ")
32+
33+
2034
def test_cli_init_and_clean() -> None:
2135
tmpdir = tempfile.mkdtemp(prefix="pn_cli_test_")
2236
try:

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL