diff --git a/casbin_cli/__version__.py b/casbin_cli/__version__.py index d538f87..5b2615d 100644 --- a/casbin_cli/__version__.py +++ b/casbin_cli/__version__.py @@ -1 +1,21 @@ -__version__ = "1.0.0" \ No newline at end of file +import subprocess + + +def get_base_tag(): + try: + command = ["git", "describe", "--tags", "--abbrev=0"] + + tag = subprocess.check_output( + command, text=True, stderr=subprocess.PIPE + ).strip() + + if tag.startswith("v"): + return tag[1:] + return tag + + except subprocess.CalledProcessError: + print("Error: Failed to find any git tags.") + return None + + +__version__ = get_base_tag() diff --git a/casbin_cli/client.py b/casbin_cli/client.py index 09809ed..e1cdea0 100644 --- a/casbin_cli/client.py +++ b/casbin_cli/client.py @@ -26,7 +26,18 @@ def run(args=None): return "" elif command_name in ['-v', '--version']: print(f"casbin-python-cli {__version__}") - print("pycasbin 1.17.0") + try: + from importlib.metadata import version + + pycasbin_version = version("pycasbin") + except ImportError: + try: + from importlib_metadata import version + + pycasbin_version = version("pycasbin") + except (ImportError, Exception): + pycasbin_version = "unknown" + print(f"pycasbin {pycasbin_version}") return "" elif command_name == 'completion': if len(args) < 2: