Skip to content

Commit ca0e4bc

Browse files
committed
fix(cli): handle argparse different behavior after python 3.9
argparse raises TypeError when non exist command is provided on Python < 3.9 but raise SystemExit with exit code == 2 on Python 3.9 this error does not break anything obviously from the user perspective, but will break our existing test 429
1 parent d09c085 commit ca0e4bc

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

commitizen/cli.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,13 @@ def main():
286286
# This is for the command required constraint in 2.0
287287
try:
288288
args = parser.parse_args()
289-
except TypeError:
290-
raise NoCommandFoundError()
289+
except (TypeError, SystemExit) as e:
290+
# https://github.com/commitizen-tools/commitizen/issues/429
291+
# argparse raises TypeError when non exist command is provided on Python < 3.9
292+
# but raise SystemExit with exit code == 2 on Python 3.9
293+
if isinstance(e, TypeError) or (isinstance(e, SystemExit) and e.code == 2):
294+
raise NoCommandFoundError()
295+
raise e
291296

292297
if args.name:
293298
conf.update({"name": args.name})

0 commit comments

Comments
 (0)