Skip to content

feat: add --version / -V flag to CLI#1698

Open
fsilvaortiz wants to merge 2 commits intogithub:mainfrom
fsilvaortiz:fix/add-version-flag
Open

feat: add --version / -V flag to CLI#1698
fsilvaortiz wants to merge 2 commits intogithub:mainfrom
fsilvaortiz:fix/add-version-flag

Conversation

@fsilvaortiz
Copy link

Summary

Adds the standard --version / -V flag to the specify CLI. Previously, running specify --version returned an error:

No such option: --version

Users had to know about the specify version subcommand instead, which is not the standard CLI convention.

Now:

$ specify --version
specify 0.1.6

$ specify -V
specify 0.1.6

The existing specify version subcommand (which shows detailed system info including template version, platform, and architecture) remains unchanged.

Closes #486

Test plan

  • specify --version prints version and exits with code 0
  • specify -V behaves the same as --version
  • specify version subcommand still works (detailed output)
  • specify --help shows --version -V in options
  • All tests pass (99/99 — 95 existing + 4 new)
  • Added 4 tests in TestVersionFlag:
    • test_version_flag_exits_zero
    • test_version_flag_prints_version
    • test_short_version_flag
    • test_version_flag_appears_in_help

AI Assistance Disclosure

This PR was drafted with assistance from Claude Code (Anthropic). All changes were reviewed and validated manually by the author.

🤖 Generated with Claude Code

Add standard --version flag as a typer callback so users can run
`specify --version` or `specify -V` to get the CLI version. The
existing `specify version` subcommand (which shows detailed system
info) remains unchanged.

Closes github#486

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds conventional --version / -V flags to the specify Typer CLI (while keeping the existing specify version subcommand for detailed system info), addressing issue #486.

Changes:

  • Introduces a global eager --version / -V option on the root Typer callback that prints the CLI version and exits.
  • Adds new CLI tests covering --version, -V, and presence of --version in --help.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/specify_cli/__init__.py Adds _version_callback and wires --version / -V into the root @app.callback() as an eager option.
tests/test_ai_skills.py Adds TestVersionFlag test cases validating the new flags and help output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 493 to 498
import importlib.metadata

try:
ver = importlib.metadata.version("specify-cli")
except Exception:
ver = "unknown"
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.

--version uses importlib.metadata.version("specify-cli") with a blanket fallback to "unknown", but the existing version subcommand / get_speckit_version() already implements a more accurate fallback (reading pyproject.toml when running from source). To avoid inconsistent/incorrect output (e.g., specify unknown when not installed as a package), reuse get_speckit_version() here or replicate the same fallback logic.

Suggested change
import importlib.metadata
try:
ver = importlib.metadata.version("specify-cli")
except Exception:
ver = "unknown"
try:
# Prefer the existing version resolution logic, which handles
# running from source (e.g., via pyproject.toml).
ver = get_speckit_version() # type: ignore[name-defined]
except Exception:
import importlib.metadata
try:
ver = importlib.metadata.version("specify-cli")
except Exception:
ver = "unknown"

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 catch — applied. _version_callback now calls get_speckit_version() directly, which already handles the pyproject.toml fallback for source-based runs. See 89e33f1.

Comment on lines 666 to 675
def test_version_flag_appears_in_help(self):
"""--version 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

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.

Copy link
Collaborator

@mnriem mnriem left a comment

Choose a reason for hiding this comment

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

Please review Copilot suggestions and apply where it makes sense and if not please indicate why it does not

Address Copilot review suggestions:
- Use get_speckit_version() instead of duplicating importlib.metadata
  logic, which provides a better fallback via pyproject.toml for
  source-based runs
- Assert both --version and -V appear in help output

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@fsilvaortiz
Copy link
Author

@mnriem Both Copilot suggestions applied in 89e33f1:

  1. Reuse get_speckit_version()_version_callback now calls it directly instead of duplicating importlib.metadata logic. This ensures consistent output (including the pyproject.toml fallback for source-based runs).
  2. Assert -V in help test — Added assert "-V" in plain to test_version_flag_appears_in_help.

All 60 tests passing.

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

specify --version flag not supported, returns error

3 participants