From 93a939672f922499839327c65d50732432859b4d Mon Sep 17 00:00:00 2001 From: Mika Westphal Date: Thu, 24 Nov 2022 09:51:49 +0100 Subject: [PATCH] Bug #52514: Patches the wrong usage of configure through text replacement This was done with text replacement, because this is a bug from argparse and it was not fixed in the last 12 years. https://github.com/python/cpython/issues/53584 --- .../python/appcenter/actions/configure.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/management/univention-appcenter/python/appcenter/actions/configure.py b/management/univention-appcenter/python/appcenter/actions/configure.py index b7b23c56b7a..54728a9b859 100644 --- a/management/univention-appcenter/python/appcenter/actions/configure.py +++ b/management/univention-appcenter/python/appcenter/actions/configure.py @@ -36,7 +36,7 @@ # from tempfile import NamedTemporaryFile -from argparse import SUPPRESS +from argparse import SUPPRESS, HelpFormatter from univention.appcenter.actions import UniventionAppAction, StoreAppAction from univention.appcenter.exceptions import ConfigureFailed @@ -52,6 +52,7 @@ class Configure(UniventionAppAction): help = 'Configure an app' def setup_parser(self, parser): + parser.formatter_class = PatchedHelpFormatter parser.add_argument('app', action=StoreAppAction, help='The ID of the App that shall be configured') parser.add_argument('--list', action='store_true', help='List all configuration options as well as their current values') parser.add_argument('--set', nargs='+', action=StoreConfigAction, metavar='KEY=VALUE', dest='set_vars', help='Sets the configuration variable. Example: --set some/variable=value some/other/variable="value 2"') @@ -135,3 +136,10 @@ def _run_configure_script(self, app, action): for line in error_file: self.fatal(line) return success + + +class PatchedHelpFormatter(HelpFormatter): + def _format_usage(self, usage, actions, groups, prefix): + usage = super()._format_usage(usage, actions, groups, prefix) + + return usage.replace(' app\n\n', ' ').replace('[-h]', '[-h] app').rstrip()