From: Zbigniew Jędrzejewski-Szmek Date: Thu, 27 Oct 2022 08:39:11 +0000 (+0200) Subject: mkosi: supress printing of argparse help on error X-Git-Tag: v14~2^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F1243%2Fhead;p=thirdparty%2Fmkosi.git 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. --- 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"