shared/verbs: add VERB_COMMON_HELP_HIDDEN macro and skip verbs with NULL help

Co-developed-by: Claude <claude@anthropic.com>
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-03-25 02:03:49 +01:00
parent 7be9bb1845
commit baae6e9476
2 changed files with 13 additions and 4 deletions
+4 -2
View File
@@ -160,6 +160,9 @@ int _verbs_get_help_table(const Verb verbs[], const Verb verbs_end[], Table **re
for (const Verb *verb = verbs; verb < verbs_end; verb++) {
assert(verb->dispatch);
if (!verb->help)
continue;
/* We indent the option string by two spaces. We could set the minimum cell width and
* right-align for a similar result, but that'd be more work. This is only used for
* display. */
@@ -170,8 +173,7 @@ int _verbs_get_help_table(const Verb verbs[], const Verb verbs_end[], Table **re
if (r < 0)
return table_log_add_error(r);
const char *help = verb->help ?: "FIXME";
_cleanup_strv_free_ char **s = strv_split(help, /* separators= */ NULL);
_cleanup_strv_free_ char **s = strv_split(verb->help, /* separators= */ NULL);
if (!s)
return log_oom();
+9 -2
View File
@@ -68,8 +68,15 @@ int _verbs_get_help_table(const Verb verbs[], const Verb verbs_end[], Table **re
#define verbs_get_help_table(ret) \
_verbs_get_help_table(ALIGN_PTR(__start_SYSTEMD_VERBS), __stop_SYSTEMD_VERBS, ret)
#define VERB_COMMON_HELP(impl) \
VERB(verb_help, "help", NULL, VERB_ANY, VERB_ANY, 0, "Show this help"); \
#define _VERB_COMMON_HELP_IMPL(impl) \
static int verb_help(int argc, char **argv, uintptr_t data, void *userdata) { \
return impl(); \
}
#define VERB_COMMON_HELP(impl) \
VERB(verb_help, "help", NULL, VERB_ANY, VERB_ANY, 0, "Show this help"); \
_VERB_COMMON_HELP_IMPL(impl)
#define VERB_COMMON_HELP_HIDDEN(impl) \
VERB(verb_help, "help", NULL, VERB_ANY, VERB_ANY, 0, NULL); \
_VERB_COMMON_HELP_IMPL(impl)