|
2 | 2 |
|
3 | 3 | import argparse |
4 | 4 | import logging |
| 5 | +import platform |
5 | 6 | import sys |
6 | 7 | from copy import deepcopy |
7 | 8 | from functools import partial |
|
13 | 14 | from decli import cli |
14 | 15 |
|
15 | 16 | from commitizen import commands, config, out, version_schemes |
| 17 | +from commitizen.__version__ import __version__ |
16 | 18 | from commitizen.exceptions import ( |
17 | 19 | CommitizenException, |
18 | 20 | ExitCode, |
@@ -102,6 +104,16 @@ def __call__( |
102 | 104 | "required": False, |
103 | 105 | "help": "comma separated error codes that won't raise error, e.g: cz -nr 1,2,3 bump. See codes at https://commitizen-tools.github.io/commitizen/exit_codes/", |
104 | 106 | }, |
| 107 | + { |
| 108 | + "name": ["-v", "--version"], |
| 109 | + "action": "store_true", |
| 110 | + "help": "Show the version of the installed commitizen", |
| 111 | + }, |
| 112 | + { |
| 113 | + "name": ["--report"], |
| 114 | + "action": "store_true", |
| 115 | + "help": "Show system information for reporting bugs", |
| 116 | + }, |
105 | 117 | ], |
106 | 118 | "subcommands": { |
107 | 119 | "title": "commands", |
@@ -629,13 +641,27 @@ class Args(argparse.Namespace): |
629 | 641 |
|
630 | 642 |
|
631 | 643 | def main() -> None: |
| 644 | + sys.excepthook = commitizen_excepthook |
| 645 | + |
632 | 646 | parser: argparse.ArgumentParser = cli(data) |
633 | 647 | argcomplete.autocomplete(parser) |
634 | 648 | # Show help if no arg provided |
635 | 649 | if len(sys.argv) == 1: |
636 | 650 | parser.print_help(sys.stderr) |
637 | 651 | raise ExpectedExit() |
638 | 652 |
|
| 653 | + # TODO(bearomorphism): mark `cz version --commitizen` as deprecated after `cz version` feature is stable |
| 654 | + if "--version" in sys.argv: |
| 655 | + out.write(__version__) |
| 656 | + raise ExpectedExit() |
| 657 | + |
| 658 | + # TODO(bearomorphism): mark `cz version --report` as deprecated after `cz version` feature is stable |
| 659 | + if "--report" in sys.argv: |
| 660 | + out.write(f"Commitizen Version: {__version__}") |
| 661 | + out.write(f"Python Version: {sys.version}") |
| 662 | + out.write(f"Operating System: {platform.system()}") |
| 663 | + raise ExpectedExit() |
| 664 | + |
639 | 665 | # This is for the command required constraint in 2.0 |
640 | 666 | try: |
641 | 667 | args, unknown_args = parser.parse_known_args() |
@@ -673,7 +699,6 @@ def main() -> None: |
673 | 699 | elif not conf.path: |
674 | 700 | conf.update({"name": "cz_conventional_commits"}) |
675 | 701 |
|
676 | | - sys.excepthook = commitizen_excepthook |
677 | 702 | if args.debug: |
678 | 703 | logging.getLogger("commitizen").setLevel(logging.DEBUG) |
679 | 704 | sys.excepthook = partial(sys.excepthook, debug=True) |
|
0 commit comments