Skip to content

Commit 74e9963

Browse files
feat: add --version flag to CLI
1 parent f983363 commit 74e9963

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/beans/cli.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Python imports
22
from datetime import datetime
3+
import importlib.metadata
34
import importlib.resources
45
import json
56
import os
@@ -51,6 +52,8 @@
5152
walk_beans_dir,
5253
)
5354

55+
VERSION = importlib.metadata.version("magic-beans")
56+
5457
app = typer.Typer()
5558
dep_app = typer.Typer()
5659
app.add_typer(dep_app, name="dep")
@@ -78,9 +81,18 @@ class RunContext(BaseModel):
7881
fields: list[str] | None = None
7982

8083

84+
def version_callback(value: bool):
85+
if value:
86+
typer.echo(f"beans {VERSION}")
87+
raise typer.Exit()
88+
89+
8190
@app.callback()
8291
def main(
8392
ctx: typer.Context,
93+
version: Annotated[
94+
bool | None, typer.Option("--version", help="Show version", callback=version_callback, is_eager=True)
95+
] = None,
8496
db: Annotated[str | None, typer.Option(help="Path to SQLite database")] = None,
8597
project: Annotated[str | None, typer.Option("--project", help="Project name from registry")] = None,
8698
json_output: Annotated[bool, typer.Option("--json", help="Output as JSON")] = False,

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)