From 945319dfd29ebb35373f91b1e108d6d5d5a3b87e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 27 Oct 2022 10:39:11 +0200 Subject: [PATCH] mkosi: supress printing of argparse help on error We build a precise error message, but then bury it under a wall of text produced by print_usage(). The printing of help (or some subset of it) on parsing error is just useless. Most likely the user made a typo in an option, and printing a few dozen lines (and more in the future) of unhelpful semi-related information is counterproductive. I'm surprised that argparse doesn't make this configurable, but looking at the code, it seems that the behaviour is hardcoded. Docs and stackoverflow also yield no hints. --- mkosi/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 5e9474175..2fbd6f3d6 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -53,6 +53,7 @@ from typing import ( Iterator, List, NamedTuple, + NoReturn, Optional, Sequence, Set, @@ -5024,6 +5025,10 @@ class ArgumentParserMkosi(argparse.ArgumentParser): # return the modified argument list return new_arg_strings + def error(self, message: str) -> NoReturn: + # This is a copy of super's method but with self.print_usage() removed + self.exit(2, f'{self.prog}: error: {message}\n') + COMPRESSION_ALGORITHMS = "zlib", "lzo", "zstd", "lz4", "xz" -- 2.47.2