feat(cli): add cz --version back and add cz --report to separate them from cz version#1798
feat(cli): add cz --version back and add cz --report to separate them from cz version#1798bearomorphism wants to merge 6 commits intomasterfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1798 +/- ##
=======================================
Coverage 98.23% 98.24%
=======================================
Files 61 61
Lines 2772 2787 +15
=======================================
+ Hits 2723 2738 +15
Misses 49 49 ☔ View full report in Codecov by Sentry. |
072aa76 to
a42800c
Compare
|
Will deprecate |
|
Good. Remember that the existing ones, under |
a42800c to
fa9331c
Compare
There was a problem hiding this comment.
Pull request overview
This PR adjusts the Commitizen CLI interface to reintroduce a top-level cz --version/-v and add a top-level cz --report, separating these concerns from the evolving cz version subcommand (per #1785).
Changes:
- Added global
--version/-vhandling to print the installed Commitizen version and exit. - Added global
--reporthandling to print system info for bug reports and exit. - Deprecated
cz version --reportandcz version --commitizenvia warnings, and updated CLI regression snapshots/tests accordingly.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_cli/test_no_argv_py_3_14_.txt | Updates help output snapshot to include global -v/--version and --report. |
| tests/test_cli/test_no_argv_py_3_13_.txt | Updates help output snapshot to include global -v/--version and --report. |
| tests/test_cli/test_no_argv_py_3_12_.txt | Updates help output snapshot to include global -v/--version and --report. |
| tests/test_cli/test_no_argv_py_3_11_.txt | Updates help output snapshot to include global -v/--version and --report. |
| tests/test_cli/test_no_argv_py_3_10_.txt | Updates help output snapshot to include global -v/--version and --report. |
| tests/test_cli/test_invalid_command_py_3_14_invalidCommand_.txt | Updates invalid-command snapshot to reflect new global options in usage. |
| tests/test_cli/test_invalid_command_py_3_14___invalid_arg_.txt | Modifies invalid-arg snapshot file content (currently emptied in this PR). |
| tests/test_cli/test_invalid_command_py_3_13_invalidCommand_.txt | Updates invalid-command snapshot to reflect new global options in usage. |
| tests/test_cli/test_invalid_command_py_3_13___invalid_arg_.txt | Modifies invalid-arg snapshot file content (currently emptied in this PR). |
| tests/test_cli/test_invalid_command_py_3_12_invalidCommand_.txt | Updates invalid-command snapshot to reflect new global options in usage. |
| tests/test_cli/test_invalid_command_py_3_12___invalid_arg_.txt | Modifies invalid-arg snapshot file content (currently emptied in this PR). |
| tests/test_cli/test_invalid_command_py_3_11_invalidCommand_.txt | Updates invalid-command snapshot to reflect new global options in usage. |
| tests/test_cli/test_invalid_command_py_3_11___invalid_arg_.txt | Modifies invalid-arg snapshot file content (currently emptied in this PR). |
| tests/test_cli/test_invalid_command_py_3_10_invalidCommand_.txt | Updates invalid-command snapshot to reflect new global options in usage. |
| tests/test_cli/test_invalid_command_py_3_10___invalid_arg_.txt | Modifies invalid-arg snapshot file content (currently emptied in this PR). |
| tests/test_cli.py | Adds tests for global --version/-v and --report behavior/precedence. |
| tests/commands/test_version_command.py | Adds tests ensuring deprecated cz version --report/--commitizen emit warnings. |
| commitizen/commands/version.py | Emits deprecation warnings for cz version --report and cz version --commitizen. |
| commitizen/cli.py | Adds global args (--version/-v, --report) and implements top-level handling logic. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if getattr(args, "report", False) and ( | ||
| not hasattr(args, "func") or args.func is not commands.Version | ||
| ): | ||
| out.write(f"Commitizen Version: {__version__}") | ||
| out.write(f"Python Version: {sys.version}") | ||
| out.write(f"Operating System: {platform.system()}") | ||
| raise ExpectedExit() |
| usage: cz [-h] [--config CONFIG] [--debug] [-n NAME] [-nr NO_RAISE] [-v] | ||
| [--report] | ||
| {init,commit,c,ls,example,info,schema,bump,changelog,ch,check,version} ... | ||
| cz: error: argument {init,commit,c,ls,example,info,schema,bump,changelog,ch,check,version}: invalid choice: 'invalidCommand' (choose from init, commit, c, ls, example, info, schema, bump, changelog, ch, check, version) |
Replace raw sys.argv checks with proper argparse-based handling by making subcommands optional. This fixes three issues: - cz version --report was intercepted by the top-level handler instead of routing to the Version command - cz -v did not work despite being registered as a shorthand for --version - cz version --report and cz version --commitizen now emit deprecation warnings directing users to use cz --report and cz --version instead Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Top-level meta flags like --version and --report now take priority even when a subcommand is also provided (e.g., cz --version bump shows the version instead of running bump). The --report flag correctly defers to the version subcommand when used as cz version --report. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…d 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>
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>
3b5f594 to
12584e3
Compare
Consolidate three separate version flag tests into a single parametrized test. Merge standalone deprecation warning tests into the existing test_version_for_showing_commitizen_version and test_version_for_showing_commitizen_system_info tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Description
As we are extending the functionality of
cz version, I think it would be better to extract the--commitizenand--reportfromcz version.Relate #1785