Skip to content

Commit ad2ecab

Browse files
fix(cli): use distinct dest for top-level --report to avoid subcommand conflict
Use dest='global_report' for the top-level --report flag so it does not share the same attribute as the version subcommand's --report. This ensures 'cz --report version' behaves as a top-level report instead of routing through the version subcommand with a deprecation warning. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 1e6afc2 commit ad2ecab

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

commitizen/cli.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ def __call__(
114114
{
115115
"name": ["--report"],
116116
"action": "store_true",
117+
"dest": "global_report",
117118
"help": "Show system information for reporting bugs",
118119
},
119120
],
@@ -662,6 +663,7 @@ class Args(argparse.Namespace):
662663
name: str | None = None
663664
no_raise: str | None = None # comma-separated string, later parsed as list[int]
664665
report: bool = False
666+
global_report: bool = False
665667
project: bool = False
666668
commitizen: bool = False
667669
verbose: bool = False
@@ -701,9 +703,7 @@ def main() -> None:
701703
out.write(__version__)
702704
raise ExpectedExit()
703705

704-
if getattr(args, "report", False) and (
705-
not hasattr(args, "func") or args.func is not commands.Version
706-
):
706+
if getattr(args, "global_report", False):
707707
out.write(f"Commitizen Version: {__version__}")
708708
out.write(f"Python Version: {sys.version}")
709709
out.write(f"Operating System: {platform.system()}")

tests/test_cli.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ def test_cz_report_flag_takes_precedence_over_subcommand(util: UtilFixture, caps
9898
assert "Commitizen Version:" in out
9999

100100

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+
101111
def test_name(util: UtilFixture, capsys):
102112
util.run_cli("-n", "cz_jira", "example")
103113
out, _ = capsys.readouterr()

0 commit comments

Comments
 (0)