|
69 | 69 |
|
70 | 70 | TEAM_DIRECTIVES_DIRNAME = "team-ai-directives" |
71 | 71 |
|
| 72 | +_PKG_NAMES = ("specify-cli", "agentic-sdlc-specify-cli") |
| 73 | + |
| 74 | + |
| 75 | +def _get_cli_version() -> str: |
| 76 | + """Try to get the CLI version from package metadata, trying known package names.""" |
| 77 | + import importlib.metadata |
| 78 | + |
| 79 | + for pkg_name in _PKG_NAMES: |
| 80 | + try: |
| 81 | + return importlib.metadata.version(pkg_name) |
| 82 | + except Exception: |
| 83 | + pass |
| 84 | + |
| 85 | + try: |
| 86 | + import tomllib |
| 87 | + |
| 88 | + pyproject_path = Path(__file__).parent.parent.parent / "pyproject.toml" |
| 89 | + if pyproject_path.exists(): |
| 90 | + with open(pyproject_path, "rb") as f: |
| 91 | + data = tomllib.load(f) |
| 92 | + return data.get("project", {}).get("version", "unknown") |
| 93 | + except Exception: |
| 94 | + pass |
| 95 | + return "unknown" |
| 96 | + |
72 | 97 |
|
73 | 98 | def _github_token(cli_token: str | None = None) -> str | None: |
74 | 99 | """Return sanitized GitHub token (cli arg takes precedence) or None.""" |
@@ -4272,26 +4297,10 @@ def check(): |
4272 | 4297 | def version(): |
4273 | 4298 | """Display version and system information.""" |
4274 | 4299 | import platform |
4275 | | - import importlib.metadata |
4276 | 4300 |
|
4277 | 4301 | show_banner() |
4278 | 4302 |
|
4279 | | - # Get CLI version from package metadata |
4280 | | - cli_version = "unknown" |
4281 | | - try: |
4282 | | - cli_version = importlib.metadata.version("specify-cli") |
4283 | | - except Exception: |
4284 | | - # Fallback: try reading from pyproject.toml if running from source |
4285 | | - try: |
4286 | | - import tomllib |
4287 | | - |
4288 | | - pyproject_path = Path(__file__).parent.parent.parent / "pyproject.toml" |
4289 | | - if pyproject_path.exists(): |
4290 | | - with open(pyproject_path, "rb") as f: |
4291 | | - data = tomllib.load(f) |
4292 | | - cli_version = data.get("project", {}).get("version", "unknown") |
4293 | | - except Exception: |
4294 | | - pass |
| 4303 | + cli_version = _get_cli_version() |
4295 | 4304 |
|
4296 | 4305 | # Fetch latest template release version |
4297 | 4306 | repo_owner = "github" |
@@ -4382,25 +4391,7 @@ def version(): |
4382 | 4391 |
|
4383 | 4392 | def get_speckit_version() -> str: |
4384 | 4393 | """Get current spec-kit version.""" |
4385 | | - import importlib.metadata |
4386 | | - |
4387 | | - try: |
4388 | | - return importlib.metadata.version("specify-cli") |
4389 | | - except Exception: |
4390 | | - # Fallback: try reading from pyproject.toml |
4391 | | - try: |
4392 | | - import tomllib |
4393 | | - |
4394 | | - pyproject_path = Path(__file__).parent.parent.parent / "pyproject.toml" |
4395 | | - if pyproject_path.exists(): |
4396 | | - with open(pyproject_path, "rb") as f: |
4397 | | - data = tomllib.load(f) |
4398 | | - return data.get("project", {}).get("version", "unknown") |
4399 | | - except Exception: |
4400 | | - # Intentionally ignore any errors while reading/parsing pyproject.toml. |
4401 | | - # If this lookup fails for any reason, we fall back to returning "unknown" below. |
4402 | | - pass |
4403 | | - return "unknown" |
| 4394 | + return _get_cli_version() |
4404 | 4395 |
|
4405 | 4396 |
|
4406 | 4397 | # ===== Preset Commands ===== |
|
0 commit comments