1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-08 08:58:27 +03:00

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.
This commit is contained in:
Mike Yuan 2024-04-22 17:40:53 +08:00
parent 48fb49f1bd
commit adaf1f7ea3
No known key found for this signature in database
GPG Key ID: 417471C0A40F58B3

View 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.");
}