Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show version number in help menu and --version option. #32

Merged
merged 2 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/communex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@

.. include:: ../../README.md
"""

import importlib.metadata

__version__ = importlib.metadata.version(__package__)
19 changes: 16 additions & 3 deletions src/communex/cli/root.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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__)