]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/verbs: show list of verbs when missing 32396/head
authorMike Yuan <me@yhndnzj.com>
Mon, 22 Apr 2024 09:40:53 +0000 (17:40 +0800)
committerMike Yuan <me@yhndnzj.com>
Mon, 22 Apr 2024 12:42:35 +0000 (20:42 +0800)
Replaces #32062

As discussed in #32062, making 'help' the default verb
is not very appealing for two reasons:

1) If the verb is missing, showing a help which is pages long
   isn't really helpful to locate the problem.
   (https://github.com/systemd/systemd/pull/32062#issuecomment-2064997158)

2) We want to reserve the right to set default verbs to be
   more useful ones, instead of help. E.g. 'busctl' lists all
   bus peers by default.

So, when there are more than 2 verbs, let's instead add
the list of available verbs to the "Command verb required"
message, that serves as a hint. That way we try to be friendlier
to users, but still make the problem obvious.

src/shared/verbs.c

index 54817252b5bf55493236b470b3bb05838e9e239a..7e7ac2a2554069e8ce14a5dd005ecc082b77722b 100644 (file)
@@ -143,6 +143,17 @@ int dispatch_verb(int argc, char *argv[], const Verb verbs[], void *userdata) {
                         return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown command verb '%s'.", name);
                 }
 
+                _cleanup_free_ char *verb_list = NULL;
+                size_t i;
+
+                for (i = 0; verbs[i].dispatch; i++)
+                        if (!strextend_with_separator(&verb_list, ", ", verbs[i].verb))
+                                return log_oom();
+
+                if (i > 2)
+                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                               "Command verb required (one of %s).", verb_list);
+
                 return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Command verb required.");
         }