diff options
author | Mike Yuan <me@yhndnzj.com> | 2024-04-22 11:40:53 +0200 |
---|---|---|
committer | Mike Yuan <me@yhndnzj.com> | 2024-04-22 14:42:35 +0200 |
commit | adaf1f7ea38798d4ddbb3cff6513188fd6e98c9e (patch) | |
tree | 38fc034399cedd5a65b8b5b70e8c76cb27f8ffcf /src/shared | |
parent | shared/verbs: minor modernization (diff) | |
download | systemd-adaf1f7ea38798d4ddbb3cff6513188fd6e98c9e.tar.xz systemd-adaf1f7ea38798d4ddbb3cff6513188fd6e98c9e.zip |
shared/verbs: show list of verbs when missing
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.
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/verbs.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/shared/verbs.c b/src/shared/verbs.c index 54817252b5..7e7ac2a255 100644 --- a/src/shared/verbs.c +++ b/src/shared/verbs.c @@ -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."); } |