Skip to content

Commit 3648019

Browse files
committed
fix: add version command to Specify CLI #811
1 parent b702fcb commit 3648019

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/specify_cli/__init__.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
import typer
3939
import httpx
40+
import importlib.metadata
4041
from rich.console import Console
4142
from rich.panel import Panel
4243
from rich.progress import Progress, SpinnerColumn, TextColumn
@@ -52,6 +53,7 @@
5253
import ssl
5354
import truststore
5455

56+
__version__ = importlib.metadata.version(__package__)
5557
ssl_context = truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
5658
client = httpx.Client(verify=ssl_context)
5759

@@ -373,9 +375,22 @@ def show_banner():
373375
console.print(Align.center(Text(TAGLINE, style="italic bright_yellow")))
374376
console.print()
375377

378+
def show_version():
379+
"""Show the application version."""
380+
typer.echo(f"{__package__} {__version__}")
381+
376382
@app.callback()
377-
def callback(ctx: typer.Context):
383+
def callback(
384+
ctx: typer.Context,
385+
version: bool = typer.Option(
386+
None, "--version", help="Show version and exit.", is_eager=True
387+
),
388+
):
378389
"""Show banner when no subcommand is provided."""
390+
if version:
391+
show_version()
392+
raise typer.Exit()
393+
379394
if ctx.invoked_subcommand is None and "--help" not in sys.argv and "-h" not in sys.argv:
380395
show_banner()
381396
console.print(Align.center("[dim]Run 'specify --help' for usage information[/dim]"))
@@ -1118,6 +1133,11 @@ def check():
11181133
if not any(agent_results.values()):
11191134
console.print("[dim]Tip: Install an AI assistant for the best experience[/dim]")
11201135

1136+
@app.command()
1137+
def version():
1138+
"""Show the application version."""
1139+
show_version()
1140+
11211141
def main():
11221142
app()
11231143

0 commit comments

Comments
 (0)