diff --git a/src/rez_pip/cli.py b/src/rez_pip/cli.py index b9442f4..3527a02 100644 --- a/src/rez_pip/cli.py +++ b/src/rez_pip/cli.py @@ -92,6 +92,13 @@ def _createParser() -> argparse.ArgumentParser: "-h", "--help", action="help", help="Show this help message and exit." ) + generalGroup.add_argument( + "-v", + "--version", + action="version", + version=importlib_metadata.version(__package__), + ) + debugGroup = parser.add_argument_group(title="debug options") debugGroup.add_argument( "-l", diff --git a/tests/test_cli.py b/tests/test_cli.py index ce827fe..ada7b07 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -13,6 +13,7 @@ import pytest import rich.console +import packaging.version import rez_pip.cli import rez_pip.pip @@ -114,6 +115,16 @@ def test_parseArgs_pipArgs(): assert pipArgs == ["adasdasd", "--requirement", "asd.txt"] +def test_version(): + result = subprocess.run( + [sys.executable, "-m", "rez_pip", "--version"], + check=True, + stdout=subprocess.PIPE, + text=True, + ) + assert packaging.version.parse(result.stdout.strip()) + + def test_validateArgs_pip_good(tmp_path: pathlib.Path): path = pathlib.Path(tmp_path / "asd.pyz")