feat: add --version / -V flag to CLI#1698
Conversation
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>
There was a problem hiding this comment.
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/-Voption on the root Typer callback that prints the CLI version and exits. - Adds new CLI tests covering
--version,-V, and presence of--versionin--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.
src/specify_cli/__init__.py
Outdated
| import importlib.metadata | ||
|
|
||
| try: | ||
| ver = importlib.metadata.version("specify-cli") | ||
| except Exception: | ||
| ver = "unknown" |
There was a problem hiding this comment.
--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.
| 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" |
There was a problem hiding this comment.
Good catch — applied. _version_callback now calls get_speckit_version() directly, which already handles the pyproject.toml fallback for source-based runs. See 89e33f1.
| 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 | ||
|
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Good point — added assert "-V" in plain to the help output test. See 89e33f1.
mnriem
left a comment
There was a problem hiding this comment.
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>
|
@mnriem Both Copilot suggestions applied in 89e33f1:
All 60 tests passing. 🤖 Generated with Claude Code |
Summary
Adds the standard
--version/-Vflag to thespecifyCLI. Previously, runningspecify --versionreturned an error:Users had to know about the
specify versionsubcommand instead, which is not the standard CLI convention.Now:
The existing
specify versionsubcommand (which shows detailed system info including template version, platform, and architecture) remains unchanged.Closes #486
Test plan
specify --versionprints version and exits with code 0specify -Vbehaves the same as--versionspecify versionsubcommand still works (detailed output)specify --helpshows--version -Vin optionsTestVersionFlag:test_version_flag_exits_zerotest_version_flag_prints_versiontest_short_version_flagtest_version_flag_appears_in_helpAI 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