|
2 | 2 | import logging
|
3 | 3 | import sys
|
4 | 4 | from functools import partial
|
| 5 | +from typing import List |
5 | 6 |
|
6 | 7 | import argcomplete
|
7 | 8 | from decli import cli
|
|
24 | 25 | "name": ["-n", "--name"],
|
25 | 26 | "help": "use the given commitizen (default: cz_conventional_commits)",
|
26 | 27 | },
|
| 28 | + { |
| 29 | + "name": ["-nr", "--no-raise"], |
| 30 | + "action": "append", |
| 31 | + "type": int, |
| 32 | + "required": False, |
| 33 | + "help": "error codes that won't rise error, provide -nr multiple times for many", |
| 34 | + }, |
27 | 35 | ],
|
28 | 36 | "subcommands": {
|
29 | 37 | "title": "commands",
|
|
268 | 276 | original_excepthook = sys.excepthook
|
269 | 277 |
|
270 | 278 |
|
271 |
| -def commitizen_excepthook(type, value, tracekback, debug=False): |
| 279 | +def commitizen_excepthook( |
| 280 | + type, value, tracekback, debug=False, no_raise: List[int] = None |
| 281 | +): |
| 282 | + if no_raise is None: |
| 283 | + no_raise = [] |
272 | 284 | if isinstance(value, CommitizenException):
|
273 | 285 | if value.message:
|
274 | 286 | value.output_method(value.message)
|
275 | 287 | if debug:
|
276 | 288 | original_excepthook(type, value, tracekback)
|
277 |
| - sys.exit(value.exit_code) |
| 289 | + exit_code = value.exit_code |
| 290 | + if exit_code in no_raise: |
| 291 | + exit_code = 0 |
| 292 | + sys.exit(exit_code) |
278 | 293 | else:
|
279 | 294 | original_excepthook(type, value, tracekback)
|
280 | 295 |
|
@@ -313,6 +328,11 @@ def main():
|
313 | 328 | if args.debug:
|
314 | 329 | logging.getLogger("commitizen").setLevel(logging.DEBUG)
|
315 | 330 | sys.excepthook = commitizen_debug_excepthook
|
| 331 | + elif args.no_raise: |
| 332 | + no_raise_debug_excepthook = partial( |
| 333 | + commitizen_excepthook, no_raise=args.no_raise |
| 334 | + ) |
| 335 | + sys.excepthook = no_raise_debug_excepthook |
316 | 336 |
|
317 | 337 | args.func(conf, vars(args))()
|
318 | 338 |
|
|
0 commit comments