From ea8d2c0d16628be838f57c5ff9876a1fbb5bf209 Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Mon, 22 Apr 2024 13:28:55 +0200 Subject: [PATCH 1/2] Improve cmdln.HelpFormatter to obey newline characters --- osc/cmdln.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/osc/cmdln.py b/osc/cmdln.py index e3fafd7b83..069677b47c 100644 --- a/osc/cmdln.py +++ b/osc/cmdln.py @@ -6,6 +6,7 @@ import argparse import inspect import sys +import textwrap def option(*args, **kwargs): @@ -78,6 +79,19 @@ def decorate(f): class HelpFormatter(argparse.RawDescriptionHelpFormatter): + def _split_lines(self, text, width): + # remove the leading and trailing whitespaces to avoid printing unwanted blank lines + text = text.strip() + + result = [] + for line in text.splitlines(): + if not line.strip(): + # textwrap normally returns [] on a string that contains only whitespaces; we want [""] to print a blank line + result.append("") + else: + result.extend(textwrap.wrap(line, width)) + return result + def _format_action(self, action): if isinstance(action, argparse._SubParsersAction): parts = [] From 9365a421ce56a8bc38136f82ea39f793159c3335 Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Mon, 22 Apr 2024 13:32:16 +0200 Subject: [PATCH 2/2] Document '--buildtool-opt=--noclean' example in 'build' command's help --- osc/commandline.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/osc/commandline.py b/osc/commandline.py index 9a7923a6cf..10113b3cdd 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -7172,7 +7172,14 @@ def parse_repoarchdescr(self, args, noinit=False, alternative_project=None, igno @cmdln.option('--build-opt', metavar='OPT', action='append', help='pass option OPT to the build command') @cmdln.option('--buildtool-opt', metavar='OPT', action='append', - help='pass option OPT to the build tool command (rpmbuild)') + help=textwrap.dedent( + """ + pass option OPT to the build tool command (rpmbuild), for example: + * don't clean build environment after a successful build: + --buildtool-opt=--noclean + """ + ), + ) @cmdln.option('--userootforbuild', '--login-as-root', action='store_true', help='Run build or shell as root. The default is to build as ' 'unprivileged user. Note that a line "# norootforbuild" '