diff --git a/src/aleph_client/__main__.py b/src/aleph_client/__main__.py index 3a414d0b..161f974e 100644 --- a/src/aleph_client/__main__.py +++ b/src/aleph_client/__main__.py @@ -4,15 +4,22 @@ import typer -from .commands import account, aggregate, files, message, program +from .commands import about, account, aggregate, files, message, program app = typer.Typer() +@app.callback() +def common( + ctx: typer.Context, + version: bool = typer.Option(None, "--version", callback=about.get_version, help="Show Aleph CLI Version"), + v: bool = typer.Option(None, "-v", callback=about.get_version, help="Show Aleph CLI Version"), +): + pass + app.add_typer(account.app, name="account", help="Manage account") app.add_typer( aggregate.app, name="aggregate", help="Manage aggregate messages on aleph.im" ) - app.add_typer( files.app, name="file", help="File uploading and pinning on IPFS and aleph.im" ) @@ -24,6 +31,9 @@ app.add_typer( program.app, name="program", help="Upload and update programs on aleph.im VM" ) +app.add_typer( + about.app, name="about", help="Display the informations of Aleph CLI" +) if __name__ == "__main__": diff --git a/src/aleph_client/commands/about.py b/src/aleph_client/commands/about.py new file mode 100644 index 00000000..e0d00dd8 --- /dev/null +++ b/src/aleph_client/commands/about.py @@ -0,0 +1,20 @@ +import typer +from pkg_resources import get_distribution + +app = typer.Typer() + + +def get_version(value: bool): + __version__ = "NaN" + dist_name = "aleph-client" + if value: + try: + __version__ = get_distribution(dist_name).version + finally: + typer.echo(f"Aleph CLI Version: {__version__}") + raise typer.Exit(1) + + +@app.command() +def version(): + get_version(True)