Repository: rapidsai/dependency-file-generator

Issue:
Please add a --version flag
This would be helpful in determining which version is installed.

Discussion:
@vyasr: PR welcome! The CLI entry point is [here](https://github.com/rapidsai/dependency-file-generator/blob/main/src/rapids_dependency_file_generator/_cli.py#L107) and I think adding a version flag should be a straightforward addition. I agree that this would be useful.@dagardner-nv: PR #130

Solution patch:
diff --git a/src/rapids_dependency_file_generator/_cli.py b/src/rapids_dependency_file_generator/_cli.py
index 1917b26..f4cad78 100644
--- a/src/rapids_dependency_file_generator/_cli.py
+++ b/src/rapids_dependency_file_generator/_cli.py
@@ -2,7 +2,7 @@ import argparse
 import os
 
 from ._config import Output, load_config_from_file
-from ._constants import default_dependency_file_path
+from ._constants import cli_name, default_dependency_file_path
 from ._rapids_dependency_file_generator import (
     delete_existing_files,
     make_dependency_files,
@@ -73,6 +73,13 @@ def validate_args(argv):
         ),
     )
 
+    parser.add_argument(
+        "--version",
+        default=False,
+        action="store_true",
+        help="Show the version and exit.",
+    )
+
     args = parser.parse_args(argv)
 
     dependent_arg_keys = ["file_key", "output", "matrix"]
@@ -107,6 +114,10 @@ def generate_matrix(matrix_arg):
 def main(argv=None) -> None:
     args = validate_args(argv)
 
+    if args.version:
+        print(f"{cli_name}, version {version}")
+        return
+
     parsed_config = load_config_from_file(args.config)
 
     matrix = generate_matrix(args.matrix)


Test patch:
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 21a05b5..9b5feb7 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -174,3 +174,10 @@ def test_validate_args():
             "build_python",
         ]
     )
+
+    # Verify --version flag
+    args = validate_args([])
+    assert not args.version
+
+    args = validate_args(["--version"])
+    assert args.version