From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3C9784399C; Mon, 22 Jan 2024 19:26:47 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 48C6A40ED2; Mon, 22 Jan 2024 19:26:37 +0100 (CET) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mails.dpdk.org (Postfix) with ESMTP id 9109140A6C for ; Mon, 22 Jan 2024 19:26:35 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3B7FA106F; Mon, 22 Jan 2024 10:27:21 -0800 (PST) Received: from localhost.localdomain (unknown [10.57.90.210]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 742E43F762; Mon, 22 Jan 2024 10:26:34 -0800 (PST) From: Luca Vizzarro To: dev@dpdk.org Cc: Luca Vizzarro , =?UTF-8?q?Juraj=20Linke=C5=A1?= , Paul Szczepanek Subject: [PATCH 2/4] dts: customise argparse error message Date: Mon, 22 Jan 2024 18:26:09 +0000 Message-Id: <20240122182611.1904974-3-luca.vizzarro@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240122182611.1904974-1-luca.vizzarro@arm.com> References: <20240122182611.1904974-1-luca.vizzarro@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org This commit customises the arguments parsing class' error message, making it so the confusing usage is not displayed in these occurrences, but the user is redirected to use the help argument instead. Reviewed-by: Paul Szczepanek Signed-off-by: Luca Vizzarro --- dts/framework/settings.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/dts/framework/settings.py b/dts/framework/settings.py index 2d0365e763..acfe5cad44 100644 --- a/dts/framework/settings.py +++ b/dts/framework/settings.py @@ -170,6 +170,15 @@ def _parse_revision_id(rev_id: str) -> str: ) +class ArgumentParser(argparse.ArgumentParser): + """ArgumentParser with a custom error message.""" + def error(self, message): + print(f"{self.prog}: error: {message}\n", file=sys.stderr) + self.exit(2, + "For help and usage, " + "run the command with the --help flag.\n") + + @dataclass(slots=True) class Settings: """Default framework-wide user settings. @@ -200,8 +209,8 @@ class Settings: SETTINGS: Settings = Settings() -def _get_parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser( +def _get_parser() -> ArgumentParser: + parser = ArgumentParser( description="Run DPDK test suites. All options may be specified with the environment " "variables provided in brackets. Command line arguments have higher priority.", formatter_class=argparse.ArgumentDefaultsHelpFormatter, -- 2.34.1