diff --git a/polyapi/cli.py b/polyapi/cli.py index 1efe663..e99cded 100644 --- a/polyapi/cli.py +++ b/polyapi/cli.py @@ -14,6 +14,16 @@ CLI_COMMANDS = ["setup", "generate", "function", "clear", "help", "update_rendered_spec"] +def _get_version_string(): + """Get the version string for the package.""" + try: + import importlib.metadata + version = importlib.metadata.version('polyapi-python') + return version + except Exception: + return "Unknown" + + def execute_from_cli(): # First we setup all our argument parsing logic # Then we parse the arguments (waaay at the bottom) @@ -22,6 +32,11 @@ def execute_from_cli(): description="Manage your Poly API configurations and functions", formatter_class=argparse.RawTextHelpFormatter ) + + # Add global --version/-v flag + parser.add_argument('-v', '--version', action='version', + version=_get_version_string(), + help="Show version information") subparsers = parser.add_subparsers(help="Available commands") diff --git a/pyproject.toml b/pyproject.toml index 99ffea9..516a121 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ requires = ["setuptools>=61.2", "wheel"] [project] name = "polyapi-python" -version = "0.3.8.dev6" +version = "0.3.8.dev7" description = "The Python Client for PolyAPI, the IPaaS by Developers for Developers" authors = [{ name = "Dan Fellin", email = "dan@polyapi.io" }] dependencies = [