]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
verbs: wrap the help footer at print time
authorZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Thu, 13 Aug 2026 11:22:24 +0000 (13:22 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Thu, 13 Aug 2026 11:48:24 +0000 (13:48 +0200)
The footer is now wrapped to min($COLUMNS, 80) when it is printed, so
CommandDescription footers do not need to be hard-wrapped in the source,
and make use of the available terminal width. Newlines embedded in the
text are preserved and each line is wrapped independently, so explicit
line breaks can still be used where needed, e.g. before the example
command line in varlinkctl.

The text is wrapped at max of 80 columns to avoid very wrong lines on
wide terminals. Such lines are hard to read.

A new helper is added for this. We already have format_strv_width in
format-table, but it requires a strv, so we'd need to conver the data,
and returns a formatted string, which we'd need to print ourselves. So
overall, it seems better to add a dedicated helper.

src/resolve/resolvconf-compat.c
src/shared/verbs.c

index 51e226da84d8c8b7132e506ee554dbebf735ca71..8e4835b4f8d8c2f8a74d0410cfaa995ab238d55d 100644 (file)
@@ -28,12 +28,12 @@ COMMAND(
         .argspec = "-a INTERFACE <FILE\0"
                    "-d INTERFACE\0",
         .footer =
-               "This is a compatibility alias for the resolvectl(1) tool, providing native\n"
-               "command line compatibility with the resolvconf(8) tool of various Linux\n"
-               "distributions and BSD systems. Some options supported by other implementations\n"
-               "are not supported and are ignored: -m, -u. Various options supported by other\n"
-               "implementations are not supported and will cause the invocation to fail:\n"
-               "-I, -i, -l, -R, -r, -v, -V, --enable-updates, --disable-updates,\n"
+               "This is a compatibility alias for the resolvectl(1) tool, providing native "
+               "command line compatibility with the resolvconf(8) tool of various Linux "
+               "distributions and BSD systems. Some options supported by other implementations "
+               "are not supported and are ignored: -m, -u. Various options supported by other "
+               "implementations are not supported and will cause the invocation to fail: "
+               "-I, -i, -l, -R, -r, -v, -V, --enable-updates, --disable-updates, "
                "--updates-are-enabled.",
         .option_namespace = "resolvconf",
 );
index ec8bfaf518f642af0dd292420c1a9d3920c7ecf7..66dc3e4994446d51fa23611db30de2a83e5b71db 100644 (file)
@@ -4,6 +4,7 @@
 
 #include "build.h"
 #include "env-util.h"
+#include "extract-word.h"
 #include "format-table.h"
 #include "help-util.h"
 #include "log.h"
@@ -430,6 +431,37 @@ static bool verbs_array_has_verbs(const Verb verbs[], const Verb verbs_end[]) {
         return false;
 }
 
+static int print_wrapped(const char *text) {
+
+        /* 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.
+         * before an example command line) can be used where needed. */
+
+        if (!text)
+                return 0;
+
+        _cleanup_strv_free_ char **lines = NULL, **lines2 = NULL;
+        int r;
+
+        size_t width = MIN(columns(), 80U);  /* This is a reasonable default. */
+
+        r = strv_split_full(&lines, text, "\n", EXTRACT_DONT_COALESCE_SEPARATORS);
+        if (r < 0)
+                return r;
+
+        r = strv_rebreak_lines(lines, width, &lines2);
+        if (r < 0)
+                return r;
+
+        /* Seperate this block from the previous input. */
+        putchar('\n');
+
+        STRV_FOREACH(line, lines2)
+                puts(*line);
+
+        return 0;
+}
+
 int _command_print_help(
                 const Verb verbs[],
                 const Verb verbs_end[],
@@ -467,8 +499,9 @@ int _command_print_help(
         if (r < 0)
                 return log_error_errno(r, "Failed to print verb&option help: %m");
 
-        if (cmd->footer)
-                printf("\n%s\n", cmd->footer);
+        r = print_wrapped(cmd->footer);
+        if (r < 0)
+                return r;
 
         r = print_man_links(cmd->man_pages);
         if (r < 0)