diff --git a/src/communex/__init__.py b/src/communex/__init__.py index 4f3e758..ce1e46f 100644 --- a/src/communex/__init__.py +++ b/src/communex/__init__.py @@ -9,3 +9,7 @@ .. include:: ../../README.md """ + +import importlib.metadata + +__version__ = importlib.metadata.version(__package__) diff --git a/src/communex/cli/root.py b/src/communex/cli/root.py index 9ac0941..9eb45a0 100644 --- a/src/communex/cli/root.py +++ b/src/communex/cli/root.py @@ -1,5 +1,7 @@ -from typing import Optional import typer +from typing import Optional, Annotated + +from communex import __version__ from .balance import balance_app from .key import key_app @@ -18,10 +20,21 @@ app.add_typer(subnet_app, name="subnet", help="Subnet operations") +def _version_callback(value: bool): + if value: + print(f"CommuneX {__version__}") + raise typer.Exit() + @app.callback() -def main(json: Optional[bool] = False): +def main(json: Optional[bool] = False, + version: Annotated[ + Optional[bool], typer.Option("--version", callback=_version_callback) + ] = None, +): """ - CommuneX CLI. + CommuneX CLI {version} This command line interface is under development and subject to change. """ + +main.__doc__ = main.__doc__.format(version=__version__)