verbs: wrap abstract too

So far there's only one multi-line abstract. But as pointed out in the
review, it's silly to handle footer but not the abstract.

help_abstract() is not reused because it only works with one-line
abstracts. (It always prints an empty line to separate paragraphs.)
So the formatting is done anew in print_wrapped(). I think this is OK,
since it's all very simple. After everything has been converted to
COMMAND() and its helpers, help_abstract() and the sister functions will
become unused and can be dropped then.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-08-13 13:52:35 +02:00
parent 7ea090f41b
commit 94af9a8b40
2 changed files with 14 additions and 6 deletions
+1 -1
View File
@@ -97,7 +97,7 @@ STATIC_DESTRUCTOR_REGISTER(arg_set_nta, strv_freep);
COMMAND(
"resolvectl\0",
"Send control commands to the network name resolution manager, or\n"
"Send control commands to the network name resolution manager, or "
"resolve domain names, IPv4 and IPv6 addresses, DNS records, and services.",
.man_pages = "resolvectl.1\0",
.option_namespace = "resolvectl",
+13 -5
View File
@@ -431,7 +431,7 @@ static bool verbs_array_has_verbs(const Verb verbs[], const Verb verbs_end[]) {
return false;
}
static int print_wrapped(const char *text) {
static int print_wrapped(const char *text, bool abstract) {
/* Print the text wrapped at spaces to the specified width. Newlines embedded in the text
* are preserved and each line is wrapped independently, so explicit line breaks (e.g.
@@ -457,7 +457,14 @@ static int print_wrapped(const char *text) {
putchar('\n');
STRV_FOREACH(line, lines2)
puts(*line);
if (abstract)
printf("%s%s%s%s\n",
ansi_highlight(),
ansi_add_italics(),
*line,
ansi_normal());
else
puts(*line);
return 0;
}
@@ -492,14 +499,15 @@ int _command_print_help(
help_cmdline(have_verbs ? "[OPTION…] COMMAND …" : "[OPTION…]");
}
if (cmd->abstract)
help_abstract(cmd->abstract);
r = print_wrapped(cmd->abstract, /* abstract= */ true);
if (r < 0)
return r;
r = print_verb_option_help(cmd, cmdverb + 1, verbs_end, options, options_end);
if (r < 0)
return log_error_errno(r, "Failed to print verb&option help: %m");
r = print_wrapped(cmd->footer);
r = print_wrapped(cmd->footer, /* abstract= */ false);
if (r < 0)
return r;