Skip to content

Commit 12584e3

Browse files
refactor(cli): simplify --report handling and update docs
Revert the global_report dest approach. Keep --report as a simple top-level flag that works only without a subcommand, matching the original intent. Update version.md and README.md to document the new cz --version/-v and cz --report top-level flags. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 9cab293 commit 12584e3

4 files changed

Lines changed: 16 additions & 26 deletions

File tree

commitizen/cli.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ def __call__(
114114
{
115115
"name": ["--report"],
116116
"action": "store_true",
117-
"dest": "global_report",
118117
"help": "Show system information for reporting bugs",
119118
},
120119
],
@@ -663,7 +662,6 @@ class Args(argparse.Namespace):
663662
name: str | None = None
664663
no_raise: str | None = None # comma-separated string, later parsed as list[int]
665664
report: bool = False
666-
global_report: bool = False
667665
project: bool = False
668666
commitizen: bool = False
669667
verbose: bool = False
@@ -703,13 +701,12 @@ def main() -> None:
703701
out.write(__version__)
704702
raise ExpectedExit()
705703

706-
if getattr(args, "global_report", False):
707-
out.write(f"Commitizen Version: {__version__}")
708-
out.write(f"Python Version: {sys.version}")
709-
out.write(f"Operating System: {platform.system()}")
710-
raise ExpectedExit()
711-
712704
if not hasattr(args, "func"):
705+
if getattr(args, "report", False):
706+
out.write(f"Commitizen Version: {__version__}")
707+
out.write(f"Python Version: {sys.version}")
708+
out.write(f"Operating System: {platform.system()}")
709+
raise ExpectedExit()
713710
raise NoCommandFoundError()
714711

715712
arguments = vars(args)

docs/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ Commitizen provides a comprehensive CLI with various commands. Here's the comple
227227
228228
| Command | Description | Alias |
229229
|---------|-------------|-------|
230+
| `cz --version` | Show installed Commitizen version | `cz -v` |
231+
| `cz --report` | Show system information for bug reports | - |
230232
| `cz init` | Initialize Commitizen configuration | - |
231233
| `cz commit` | Create a new commit | `cz c` |
232234
| `cz bump` | Bump version and update changelog | - |

docs/commands/version.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
Get the version of the installed Commitizen or the current project (default: installed commitizen).
22

3+
## Quick version and report
4+
5+
The following top-level flags are available for convenience:
6+
7+
- **`cz --version`** (or **`cz -v`**): print the installed Commitizen version and exit.
8+
- **`cz --report`**: print system information (Commitizen version, Python version, operating system) useful for bug reports, and exit.
9+
310
## Usage
411

512
![cz version --help](../images/cli_help/cz_version___help.svg)
@@ -20,6 +27,8 @@ Get the version of the installed Commitizen or the current project (default: ins
2027
## Examples
2128

2229
```bash
30+
cz --version # quick: installed commitizen version
31+
cz --report # quick: system info for bug reports
2332
cz version --project
2433
cz version 2.0.0 --next MAJOR
2534
cz version --project --major

tests/test_cli.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,24 +90,6 @@ def test_cz_with_report_arg(util: UtilFixture, capsys):
9090
assert "Operating System:" in out
9191

9292

93-
def test_cz_report_flag_takes_precedence_over_subcommand(util: UtilFixture, capsys):
94-
"""Test that --report takes precedence over non-version subcommands."""
95-
with pytest.raises(ExpectedExit):
96-
util.run_cli("--report", "bump")
97-
out, _ = capsys.readouterr()
98-
assert "Commitizen Version:" in out
99-
100-
101-
def test_cz_report_flag_takes_precedence_over_version_subcommand(
102-
util: UtilFixture, capsys
103-
):
104-
"""Test that top-level --report takes precedence over version subcommand."""
105-
with pytest.raises(ExpectedExit):
106-
util.run_cli("--report", "version")
107-
out, _ = capsys.readouterr()
108-
assert "Commitizen Version:" in out
109-
110-
11193
def test_name(util: UtilFixture, capsys):
11294
util.run_cli("-n", "cz_jira", "example")
11395
out, _ = capsys.readouterr()

0 commit comments

Comments
 (0)