From c02255980bc3b8f4c536e37907134b965136c848 Mon Sep 17 00:00:00 2001 From: danielshih Date: Thu, 16 Oct 2025 13:19:25 +0800 Subject: [PATCH 1/2] support check env version command for better support issue and understand using version. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit specify --version & -v specify version 0.0.20 specify --help ███████╗██████╗ ███████╗ ██████╗██╗███████╗██╗ ██╗ ██╔════╝██╔══██╗██╔════╝██╔════╝██║██╔════╝╚██╗ ██╔╝ ███████╗██████╔╝█████╗ ██║ ██║█████╗ ╚████╔╝ ╚════██║██╔═══╝ ██╔══╝ ██║ ██║██╔══╝ ╚██╔╝ ███████║██║ ███████╗╚██████╗██║██║ ██║ ╚══════╝╚═╝ ╚══════╝ ╚═════╝╚═╝╚═╝ ╚═╝ GitHub Spec Kit - Spec-Driven Development Toolkit Usage: specify [OPTIONS] COMMAND [ARGS]... Setup tool for Specify spec-driven development projects ╭─ Options ──────────────────────────────────────────────────────────────────────────╮ │ --version -v Show the version and exit │ │ --help Show this message and exit. │ ╰────────────────────────────────────────────────────────────────────────────────────╯ ╭─ Commands ─────────────────────────────────────────────────────────────────────────╮ │ init Initialize a new Specify project from the latest template. │ │ check Check that all required tools are installed. │ ╰────────────────────────────────────────────────────────────────────────────────────╯ --- src/specify_cli/__init__.py | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/specify_cli/__init__.py b/src/specify_cli/__init__.py index 56a7bf6e0..83598bbb3 100644 --- a/src/specify_cli/__init__.py +++ b/src/specify_cli/__init__.py @@ -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 @@ -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): @@ -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]")) @@ -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" ) From f43b8647144085aca4f1e2aeebe5f79802302f51 Mon Sep 17 00:00:00 2001 From: danielshih Date: Thu, 16 Oct 2025 13:27:29 +0800 Subject: [PATCH 2/2] __package__ to dynamically determine the package name, avoiding hardcoding. --- src/specify_cli/__init__.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/specify_cli/__init__.py b/src/specify_cli/__init__.py index 83598bbb3..e53b34548 100644 --- a/src/specify_cli/__init__.py +++ b/src/specify_cli/__init__.py @@ -342,13 +342,19 @@ def run_selection_loop(): return selected_key def get_version() -> str: - """Get the current version of the specify-cli package. + """Get the current version of the CLI package. Returns: Version string from package metadata, or "unknown (development mode)" if not installed. + + Note: + Uses __package__ to dynamically determine the package name, avoiding hardcoding. """ try: - return version("specify-cli") + # Use __package__ to get the current package name dynamically + package_name = __package__ or "specify_cli" + dist_name = package_name.replace("_", "-") + return version(dist_name) except PackageNotFoundError: return "unknown (development mode)"