Skip to content

Commit 799e373

Browse files
committed
feat(cli): enable displaying all traceback for CommitizenException when --debug flag is used
1 parent 4bfff4d commit 799e373

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

commitizen/cli.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
import sys
44
import warnings
5+
from functools import partial
56

67
from decli import cli
78

@@ -241,15 +242,19 @@
241242
original_excepthook = sys.excepthook
242243

243244

244-
def commitizen_excepthook(type, value, tracekback):
245+
def commitizen_excepthook(type, value, tracekback, debug=False):
245246
if isinstance(value, CommitizenException):
246247
if value.message:
247248
value.output_method(value.message)
249+
if debug:
250+
original_excepthook(type, value, tracekback)
248251
sys.exit(value.exit_code)
249252
else:
250253
original_excepthook(type, value, tracekback)
251254

252255

256+
commitizen_debug_excepthook = partial(commitizen_excepthook, debug=True)
257+
253258
sys.excepthook = commitizen_excepthook
254259

255260

@@ -284,14 +289,8 @@ def main():
284289
args.func = commands.Version
285290

286291
if args.debug:
287-
warnings.warn(
288-
(
289-
"Debug will be deprecated in next major version. "
290-
"Please remove it from your scripts"
291-
),
292-
category=DeprecationWarning,
293-
)
294292
logging.getLogger("commitizen").setLevel(logging.DEBUG)
293+
sys.excepthook = commitizen_debug_excepthook
295294

296295
# TODO: This try block can be removed after command is required in 2.0
297296
# Handle the case that argument is given, but no command is provided

tests/test_cli.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,5 @@ def test_arg_version(mocker, capsys):
7373
def test_arg_debug(mocker):
7474
testargs = ["cz", "--debug", "info"]
7575
mocker.patch.object(sys, "argv", testargs)
76-
77-
with pytest.warns(DeprecationWarning) as record:
78-
cli.main()
79-
80-
assert record[0].message.args[0] == (
81-
"Debug will be deprecated in next major version. "
82-
"Please remove it from your scripts"
83-
)
76+
cli.main()
77+
assert sys.excepthook.keywords.get("debug") is True

0 commit comments

Comments
 (0)