From 887a2a88791455c494da4afb870eeda385b3f852 Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Fri, 13 Dec 2024 10:29:20 +0100 Subject: just-lock: Improve error handling of command line parsing --- bin/just-lock.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'bin/just-lock.py') diff --git a/bin/just-lock.py b/bin/just-lock.py index a0e7cfe9..8d292ff1 100755 --- a/bin/just-lock.py +++ b/bin/just-lock.py @@ -20,7 +20,7 @@ import subprocess import sys import tempfile -from argparse import ArgumentParser +from argparse import ArgumentParser, ArgumentError from pathlib import Path from typing import Any, Dict, List, NoReturn, Optional, Set, Tuple, Union, cast @@ -888,7 +888,9 @@ def lock_config(input_file: str) -> Json: def main(): parser = ArgumentParser( prog="just-lock", - description="Generate or update a multi-repository configuration file") + description="Generate or update a multi-repository configuration file", + exit_on_error=False, # catch parsing errors ourselves + ) parser.add_argument("-C", dest="input_file", help="Input configuration file", @@ -909,7 +911,12 @@ def main(): dest="launcher", help="Local launcher to use for commands in imports", metavar="JSON") - args = parser.parse_args() + + try: + args = parser.parse_args() + except ArgumentError as err: + fail("Failed parsing command line arguments with:\n%s" % + (err.message, )) # Get the path of the input file if args.input_file: -- cgit v1.2.3