Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 14 additions & 1 deletion src/specify_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,21 @@ def show_banner():
console.print(Align.center(Text(TAGLINE, style="italic bright_yellow")))
console.print()

def _version_callback(value: bool):
"""Print CLI version and exit."""
if value:
ver = get_speckit_version()
print(f"specify {ver}")
raise typer.Exit()


@app.callback()
def callback(ctx: typer.Context):
def callback(
ctx: typer.Context,
version: Optional[bool] = typer.Option(
None, "--version", "-V", help="Show version and exit.", callback=_version_callback, is_eager=True
),
):
"""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()
Expand Down
43 changes: 43 additions & 0 deletions tests/test_ai_skills.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,49 @@ def test_ai_skills_flag_appears_in_help(self):
assert "agent skills" in plain.lower()


class TestVersionFlag:
"""Test --version flag (GitHub issue #486)."""

def test_version_flag_exits_zero(self):
"""--version should exit with code 0."""
from typer.testing import CliRunner

runner = CliRunner()
result = runner.invoke(app, ["--version"])

assert result.exit_code == 0

def test_version_flag_prints_version(self):
"""--version should print 'specify <version>'."""
from typer.testing import CliRunner

runner = CliRunner()
result = runner.invoke(app, ["--version"])

assert result.output.strip().startswith("specify ")

def test_short_version_flag(self):
"""-V should behave the same as --version."""
from typer.testing import CliRunner

runner = CliRunner()
result = runner.invoke(app, ["-V"])

assert result.exit_code == 0
assert result.output.strip().startswith("specify ")

def test_version_flag_appears_in_help(self):
"""--version and -V should appear in the help output."""
from typer.testing import CliRunner

runner = CliRunner()
result = runner.invoke(app, ["--help"])

plain = re.sub(r'\x1b\[[0-9;]*m', '', result.output)
assert "--version" in plain
assert "-V" in plain

Comment on lines 666 to 676
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description/test plan claims specify --help shows both --version and -V, but this test only asserts --version is present. Consider also asserting -V appears in the help output so the short flag is covered.

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point — added assert "-V" in plain to the help output test. See 89e33f1.


class TestParameterOrderingIssue:
"""Test fix for GitHub issue #1641: parameter ordering issues."""

Expand Down