From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 4/4] Documentation: gen_commands: deduplicate entries from multiple definitions
Date: Mon, 24 Aug 2026 13:55:34 +0200 [thread overview]
Message-ID: <20260824115619.3148656-4-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20260824115619.3148656-1-a.fatoum@pengutronix.de>
Some commands, like cpuinfo, are defined once per architecture with
identical BAREBOX_CMD_DESC/OPTS/HELP blocks. When several such
definitions end up in one parse run, the generated rst repeated the
description, usage string and every option once per definition:
https://www.barebox.org/doc/2026.07.0/commands/info/cpuinfo.html
Deduplicate descriptions, usage strings and option lists before
emitting them, and join multiple usage strings with a space instead of
concatenating them back to back. Also preserve leading indentation of
help text lines by only stripping trailing whitespace, so preformatted
help text is not flattened.
Assisted-by: Claude:fable-5
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
Documentation/gen_commands.py | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/Documentation/gen_commands.py b/Documentation/gen_commands.py
index 1a7353a854cd..04d7cc3b435a 100755
--- a/Documentation/gen_commands.py
+++ b/Documentation/gen_commands.py
@@ -57,7 +57,7 @@ def parse_c(name):
elif x := HELP_TEXT.match(line):
last = cmd['h_post' if 'h_opts' in cmd else 'h_pre']
- last.append(string_escape_literal(x.group(1)).strip())
+ last.append(string_escape_literal(x.group(1)).rstrip())
elif x := HELP_OPT.match(line):
last = cmd['h_opts']
@@ -97,6 +97,17 @@ def parse_c(name):
cmd = last = None
+def uniq(seq):
+ seen = set()
+ out = []
+ for x in seq:
+ key = tuple(x) if isinstance(x, list) else x
+ if key not in seen:
+ seen.add(key)
+ out.append(x)
+ return out
+
+
def gen_rst(name, cmd):
out = []
out.append('.. index:: %s (command)' % name)
@@ -104,7 +115,7 @@ def gen_rst(name, cmd):
out.append('.. _command_%s:' % name)
out.append('')
if 'c_desc' in cmd:
- out.append("%s - %s" % (string_escape(name), ''.join(cmd['c_desc']).strip()))
+ out.append("%s - %s" % (string_escape(name), ''.join(uniq(cmd['c_desc'])).strip()))
else:
out.append("%s" % (string_escape(name),))
out.append('=' * len(out[-1]))
@@ -112,7 +123,7 @@ def gen_rst(name, cmd):
if 'c_opts' in cmd:
out.append('Usage')
out.append('^' * len(out[-1]))
- out.append('``%s %s``' % (name, ''.join(cmd['c_opts']).strip()))
+ out.append('``%s %s``' % (name, ' '.join(uniq(cmd['c_opts'])).strip()))
out.append('')
if 'h_pre' in cmd:
pre = cmd['h_pre']
@@ -129,7 +140,7 @@ def gen_rst(name, cmd):
if 'h_opts' in cmd:
out.append('Options')
out.append('^' * len(out[-1]))
- for o, d in cmd['h_opts']:
+ for o, d in uniq(cmd['h_opts']):
o = o.strip()
d = d.strip()
if o:
--
2.47.3
next prev parent reply other threads:[~2026-08-24 11:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 11:55 [PATCH 1/4] commands: fix typos and punctuation in help texts Ahmad Fatoum
2026-08-24 11:55 ` [PATCH 2/4] commands: fix stale option strings in usage lines Ahmad Fatoum
2026-08-24 11:55 ` [PATCH 3/4] commands: fix wrong and incomplete help texts Ahmad Fatoum
2026-08-24 11:55 ` Ahmad Fatoum [this message]
2026-08-24 12:30 ` [PATCH 1/4] commands: fix typos and punctuation in " Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260824115619.3148656-4-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox