Skip to content

Commit fbfdbb8

Browse files
authored
refactor(cli): standardize --version/-V output and remove version subcommand (#23)
<!-- SPDX-License-Identifier: MIT SPDX-FileCopyrightText: 2025 py7zz contributors --> # refactor(cli): standardize --version/-V output; remove version subcommand ## Summary Standardizes CLI version reporting to common conventions: `--version`/`-V` prints the plain version string only. Removes the `py7zz version` subcommand and non‑standard fields from CLI output. ## Motivation - Align with mainstream Python CLIs (pip, pytest, black, uv) - Prevent environment‑dependent fields in CLI output - Keep py7zz CLI minimal; delegate details to the Python API ## Changes - CLI: standardize `--version`/`-V` to print only the version string; remove `py7zz version` - Docs: update `docs/VERSION_STRATEGY.md` examples to `--version`/`-V` - Tests: switch CLI version tests to `--version` - Changelog: record under Unreleased for v1.1.1 ## Compatibility & Migration - Replace any `py7zz version` usage with `py7zz --version` (or `-V`) - For detailed metadata, use `py7zz.get_version_info()` in Python ## User Impact & Migration - If you previously relied on `py7zz version`: - Replace with `py7zz --version` (or `py7zz -V`). - If you parsed extra fields from CLI output: - Use the Python API for detailed info: `py7zz.get_version_info()`. ## Testing - Update unit tests for CLI behavior - Verify pre‑commit (ruff/mypy) and CI workflows pass ## Documentation - Update version usage in `docs/VERSION_STRATEGY.md` - No changes required to README API examples ## Changelog - Unreleased: - Changed: “CLI Version Command: Standardized to `--version`/`-V` and prints only the version string.” - Removed: “`py7zz version` subcommand and non‑standard fields from CLI output.” ## Checklist - [x] Conventional Commits title - [x] Tests updated and passing - [x] Docs updated - [x] Changelog updated (Unreleased) - [x] No unrelated changes
2 parents 868eadb + 3c5cf10 commit fbfdbb8

File tree

5 files changed

+32
-56
lines changed

5 files changed

+32
-56
lines changed

CHANGELOG.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212

1313
## [Unreleased]
1414

15-
## [1.1.1] - 2025-09-07
16-
1715
### Fixed
1816
- **Filename Listing and Reading with Spaces**: Preserve multiple consecutive spaces and avoid truncation when listing contents; `read()` reliably locates files like `puzzles/puzzle 10.txt`.
1917
- **Robust Listing Parser**: Accept minimal `-slt` outputs without separators, improving reliability of `infolist()` and `open()` across environments.
2018

2119
### Changed
2220
- **List Methods Consistency**: `namelist()` and `getnames()` return files only (directories excluded) for consistency with `zipfile.ZipFile`; both methods now return the same results.
21+
- **CLI Version Command**: Standardized to `--version`/`-V` and now prints only the version string (no extra fields).
2322

2423
### Security
2524
- **Sensitive Data Protection**: Debug logging avoids exposing passwords by masking command arguments when a password is provided.
2625

26+
### Removed
27+
- **CLI Subcommand**: Removed `py7zz version` subcommand and non-standard fields (release type, GitHub tag/changelog link) from CLI output.
28+
2729
## [1.1.0] - 2025-08-10
2830

2931
### Fixed
@@ -114,8 +116,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
114116
- **7-Zip Integration**: Bundled 7zz binary for seamless archive operations
115117
- **Python API**: Comprehensive Python interface for archive manipulation
116118

117-
[Unreleased]: https://github.com/rxchi1d/py7zz/compare/v1.1.1...HEAD
118-
[1.1.1]: https://github.com/rxchi1d/py7zz/compare/v1.1.0...v1.1.1
119+
[Unreleased]: https://github.com/rxchi1d/py7zz/compare/v1.1.0...HEAD
119120
[1.1.0]: https://github.com/rxchi1d/py7zz/compare/v1.0.0...v1.1.0
120121
[1.0.1]: https://github.com/rxchi1d/py7zz/compare/v1.0.0...v1.0.1
121122
[1.0.0]: https://github.com/rxchi1d/py7zz/compare/v0.1.1...v1.0.0

docs/VERSION_STRATEGY.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,20 +197,16 @@ pip install --pre py7zz
197197
```python
198198
import py7zz
199199
print(py7zz.get_version()) # Current version
200-
print(py7zz.get_version_info()) # Complete details
200+
print(py7zz.get_version_info()) # Complete details (Python API)
201201

202-
# CLI
203-
py7zz --version # Version information
204-
py7zz version # Detailed version info
202+
# CLI (standard)
203+
py7zz --version # Version string
204+
py7zz -V # Alias for --version
205205
```
206206

207207
#### Command Line
208208
```bash
209-
# Version information
210-
py7zz version
211-
py7zz version --format json
212-
213-
# Quick version check
209+
# Quick version check (standard CLI flags)
214210
py7zz --version
215211
py7zz -V
216212
```

py7zz/bundled_info.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import subprocess
1212
from typing import Dict, Union
1313

14-
from .version import get_version
14+
from .version import get_version, get_version_type
1515

1616
# Version registry containing all version information
1717
VERSION_REGISTRY: Dict[str, Dict[str, Union[str, None]]] = {
@@ -113,10 +113,19 @@ def get_version_info() -> Dict[str, Union[str, None]]:
113113
except Exception:
114114
bundled_7zz_version = "unknown"
115115

116+
# Determine release type: prefer registry, otherwise derive from version string
117+
release_type = info.get("release_type")
118+
if not isinstance(release_type, str) or release_type == "unknown":
119+
try:
120+
derived = get_version_type(current_version)
121+
release_type = derived
122+
except Exception:
123+
release_type = "unknown"
124+
116125
return {
117126
"py7zz_version": current_version,
118127
"bundled_7zz_version": bundled_7zz_version,
119-
"release_type": info.get("release_type", "unknown"),
128+
"release_type": release_type,
120129
"release_date": info.get("release_date", "unknown"),
121130
"github_tag": info.get("github_tag", f"v{current_version}"),
122131
"changelog_url": info.get(

py7zz/cli.py

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,13 @@
77
py7zz's value is in automatic binary management and providing Python API.
88
"""
99

10-
import json
1110
import os
1211
import subprocess
1312
import sys
1413

15-
from .bundled_info import get_version_info
1614
from .core import find_7z_binary
1715

18-
19-
def print_version_info(format_type: str = "human") -> None:
20-
"""Print version information in specified format."""
21-
try:
22-
info = get_version_info()
23-
24-
if format_type == "json":
25-
# Only include essential info in JSON output
26-
essential_info = {
27-
"py7zz_version": info["py7zz_version"],
28-
"bundled_7zz_version": info["bundled_7zz_version"],
29-
}
30-
print(json.dumps(essential_info, indent=2))
31-
else:
32-
print(f"py7zz version: {info['py7zz_version']}")
33-
print(f"Bundled 7zz version: {info['bundled_7zz_version']}")
34-
except Exception as e:
35-
print(f"py7zz error: {e}", file=sys.stderr)
36-
sys.exit(1)
16+
## Intentionally minimal: CLI only exposes --version/-V for version string
3717

3818

3919
def main() -> None:
@@ -47,29 +27,19 @@ def main() -> None:
4727
4. py7zz focuses on Python API and binary management
4828
"""
4929
try:
50-
# Handle py7zz-specific commands
30+
# Handle py7zz-specific minimal commands
5131
if len(sys.argv) > 1:
5232
command = sys.argv[1]
5333

54-
if command == "version":
55-
# Handle version command
56-
format_type = "human"
57-
if len(sys.argv) > 2 and sys.argv[2] == "--format":
58-
if len(sys.argv) > 3:
59-
format_type = sys.argv[3]
60-
else:
61-
print(
62-
"Error: --format requires a value (human or json)",
63-
file=sys.stderr,
64-
)
65-
sys.exit(1)
66-
67-
print_version_info(format_type)
68-
return
34+
if command in ["--version", "-V"]:
35+
# Handle quick version command: print only version string
36+
try:
37+
from .version import get_version as _get_version
6938

70-
elif command in ["--py7zz-version", "-V"]:
71-
# Handle quick version command
72-
print_version_info("human")
39+
print(_get_version())
40+
except Exception as _e:
41+
print(f"py7zz error: {_e}", file=sys.stderr)
42+
sys.exit(1)
7343
return
7444

7545
# Get py7zz-managed 7zz binary

tests/test_pypi_version_validation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def test_cli_version_command(self):
282282
"""Test CLI version command."""
283283
# Test that CLI version command works
284284
result = subprocess.run(
285-
["python", "-m", "py7zz", "--py7zz-version"],
285+
["python", "-m", "py7zz", "--version"],
286286
capture_output=True,
287287
text=True,
288288
cwd=Path(__file__).parent.parent,

0 commit comments

Comments
 (0)