Skip to content

Commit

Permalink
Feature: Expose Aleph CLI Version #168 (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
aliel authored Nov 9, 2023
1 parent 2a902a9 commit 74fba9c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/aleph_client/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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__":
Expand Down
20 changes: 20 additions & 0 deletions src/aleph_client/commands/about.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 74fba9c

Please sign in to comment.