verbs: introduce VERB_COMMON_HELP_AUTO{,_HIDDEN}

This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-08-13 13:23:04 +02:00
parent 0ebe40080e
commit 0059c3f5f2
2 changed files with 12 additions and 7 deletions
+2 -7
View File
@@ -14,7 +14,6 @@
#include "main-func.h"
#include "options.h"
#include "parse-argument.h"
#include "pretty-print.h"
#include "string-util.h"
#include "strv.h"
#include "verbs.h"
@@ -234,11 +233,7 @@ static int verb_show(int argc, char *argv[], uintptr_t _data, void *userdata) {
return 0;
}
static int help(void) {
return command_print_help("systemd-id128");
}
VERB_COMMON_HELP(help);
VERB_COMMON_HELP_AUTO("systemd-id128");
static int parse_argv(int argc, char *argv[], char ***ret_args) {
int r;
@@ -251,7 +246,7 @@ static int parse_argv(int argc, char *argv[], char ***ret_args) {
FOREACH_OPTION_OR_RETURN(c, &opts)
switch (c) {
OPTION_COMMON_HELP:
return help();
return command_print_help("systemd-id128");
OPTION_COMMON_VERSION:
return version();
+10
View File
@@ -125,6 +125,12 @@ int _verbs_get_help_table(
VERB(verb_help, "help", NULL, VERB_ANY, VERB_ANY, 0, NULL); \
_VERB_COMMON_HELP_IMPL(impl)
#define VERB_COMMON_HELP_AUTO(program) \
VERB_FULL(verb_help_auto, "help", NULL, VERB_ANY, VERB_ANY, 0, (uintptr_t) program, "Show this help")
#define VERB_COMMON_HELP_AUTO_HIDDEN(program) \
VERB_FULL(verb_help_auto, "help", NULL, VERB_ANY, VERB_ANY, 0, (uintptr_t) program, NULL)
int _command_print_help(
const Verb verbs[],
const Verb verbs_end[],
@@ -136,3 +142,7 @@ int _command_print_help(
__start_SYSTEMD_VERBS, __stop_SYSTEMD_VERBS, \
__start_SYSTEMD_OPTIONS, __stop_SYSTEMD_OPTIONS, \
name)
static inline int verb_help_auto(int argc, char **argv, uintptr_t data, void *userdata) {
return command_print_help((const char*) ASSERT_PTR(data));
}