shared/verbs: add flag VERB_DEPRECATED

Previously, verbs were skipped in --help automatically when their
.help field was nil. But this doesn't work in two ways:
- in introspection data we want to show the option, but marked as
  deprecated
- in udevadm (and maybe other programs with verbs with own options in
  the future), we need to show help for the verb.

So add an explicit flag to mark verbs as deprecated and skip them in
help even if .help is set. If there's a footer, print it highlighted
in red automatically.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-08-28 09:29:04 +02:00
parent 4aea8cedd2
commit 868d22628c
3 changed files with 9 additions and 4 deletions
+7 -3
View File
@@ -312,8 +312,8 @@ int _verbs_get_help_table(
if (group_marker)
break; /* End of group */
if (!verb->help)
/* No help string — we do not show the verb */
if (FLAGS_SET(verb->flags, VERB_DEPRECATED) || !verb->help)
/* Marked as deprecated or no help string — we do not show the verb */
continue;
r = verb_add_help_one(table, verb);
@@ -629,7 +629,8 @@ int _command_print_verb_help(
return r;
}
r = print_wrapped(verb->footer, /* footer_ansi_seq= */ NULL);
r = print_wrapped(verb->footer,
FLAGS_SET(verb->flags, VERB_DEPRECATED) ? ansi_highlight_red() : NULL);
if (r < 0)
return r;
@@ -688,6 +689,9 @@ static int verb_build_json(
SD_JSON_BUILD_PAIR_CONDITION(
FLAGS_SET(verb->flags, VERB_DEFAULT),
"isDefault", SD_JSON_BUILD_BOOLEAN(true)),
SD_JSON_BUILD_PAIR_CONDITION(
FLAGS_SET(verb->flags, VERB_DEPRECATED),
"isDeprecated", SD_JSON_BUILD_BOOLEAN(true)),
SD_JSON_BUILD_PAIR_CONDITION(
FLAGS_SET(verb->flags, VERB_ONLINE_ONLY),
"isOnlineOnly", SD_JSON_BUILD_BOOLEAN(true)));
+1
View File
@@ -33,6 +33,7 @@ typedef enum VerbFlags {
VERB_OPTION_REQUIRED = 1 << 2, /* The verb always requires an option to be present */
VERB_COMMAND_MARKER = 1 << 3, /* Header entry with command description */
VERB_GROUP_MARKER = 1 << 4, /* Fake verb entry to separate groups */
VERB_DEPRECATED = 1 << 5, /* The verb is deprecated and not listed in help. */
} VerbFlags;
/* Note: see the comment on struct Option in options.h for why _alignptr_ is required here. */
+1 -1
View File
@@ -99,7 +99,7 @@ static const Verb introspect_verbs[] = {
.argspec = "FORM1\0FORM2…\0", .help = "Alpha verb", .option_namespace = "test-verbs-alpha" },
{ .verb = "beta", .min_args = VERB_ANY, .max_args = VERB_ANY, .dispatch = noop_dispatcher,
.help = "Beta verb" },
{ .verb = "gamma", .flags = VERB_OPTION_REQUIRED,
{ .verb = "gamma", .flags = VERB_OPTION_REQUIRED | VERB_DEPRECATED,
.min_args = VERB_ANY, .max_args = VERB_ANY, .dispatch = noop_dispatcher,
.help = "Gamma verb", .footer = "Gamma footer" },
{}