Skip to content
Closed
Changes from 1 commit
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
35 changes: 31 additions & 4 deletions src/specify_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import json
from pathlib import Path
from typing import Optional, Tuple
from importlib.metadata import version, PackageNotFoundError

import typer
import httpx
Expand Down Expand Up @@ -340,6 +341,17 @@ def run_selection_loop():

return selected_key

def get_version() -> str:
"""Get the current version of the specify-cli package.

Returns:
Version string from package metadata, or "unknown (development mode)" if not installed.
"""
try:
return version("specify-cli")
except PackageNotFoundError:
return "unknown (development mode)"

console = Console()

class BannerGroup(TyperGroup):
Expand Down Expand Up @@ -374,8 +386,23 @@ def show_banner():
console.print()

@app.callback()
def callback(ctx: typer.Context):
"""Show banner when no subcommand is provided."""
def callback(
ctx: typer.Context,
version_flag: bool = typer.Option(
False,
"--version",
"-v",
help="Show the version and exit",
is_eager=True
)
):
"""Show banner when no subcommand is provided, or version if requested."""
# Handle version flag first (eager option)
if version_flag:
console.print(f"specify version {get_version()}")
raise typer.Exit()

# Show banner when no subcommand is provided
if ctx.invoked_subcommand is None and "--help" not in sys.argv and "-h" not in sys.argv:
show_banner()
console.print(Align.center("[dim]Run 'specify --help' for usage information[/dim]"))
Expand Down Expand Up @@ -895,8 +922,8 @@ def init(
# Create options dict for selection (agent_key: display_name)
ai_choices = {key: config["name"] for key, config in AGENT_CONFIG.items()}
selected_ai = select_with_arrows(
ai_choices,
"Choose your AI assistant:",
ai_choices,
"Choose your AI assistant:",
"copilot"
)

Expand Down