]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/options: allow option help to be extended with fake lines
authorZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Tue, 24 Mar 2026 10:01:37 +0000 (11:01 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Wed, 25 Mar 2026 01:02:20 +0000 (02:02 +0100)
Useful when we want to enumerate options rvalues with custom help
texts.

src/shared/options.c
src/shared/options.h

index 3847bd648c1fa6ab7627d085813161cf47daabea..8ea22c9b7a18d63e862800062f385fe9c53552d0 100644 (file)
@@ -21,7 +21,8 @@ static bool option_arg_required(const Option *opt) {
 
 static bool option_is_metadata(const Option *opt) {
         /* A metadata entry that is not a real option, like the group marker */
-        return FLAGS_SET(ASSERT_PTR(opt)->flags, OPTION_GROUP_MARKER);
+        return  FLAGS_SET(ASSERT_PTR(opt)->flags, OPTION_GROUP_MARKER) ||
+                FLAGS_SET(ASSERT_PTR(opt)->flags, OPTION_HELP_ENTRY);
 }
 
 static void kill_arg(char* argv[], int argc, int index) {
@@ -274,8 +275,6 @@ int _option_parser_get_help_table(
                 if (group_marker)
                         break;  /* End of group */
 
-                assert(!option_is_metadata(opt));
-
                 if (!opt->help)
                         /* No help string — we do not show the option */
                         continue;
index bae42cdcf61cfc31bc5dc948614a148f8935eaa3..fd2d048db00c495776620c80d4cf167abf1c27da 100644 (file)
@@ -8,6 +8,7 @@ typedef enum OptionFlags {
         OPTION_OPTIONAL_ARG  = 1U << 0,  /* Same as optional_argument in getopt */
         OPTION_STOPS_PARSING = 1U << 1,  /* This option acts like "--" */
         OPTION_GROUP_MARKER  = 1U << 2,  /* Fake option entry to separate groups */
+        OPTION_HELP_ENTRY    = 1U << 3,  /* Fake option entry to insert an additional help line */
 } OptionFlags;
 
 typedef struct Option {
@@ -44,7 +45,9 @@ typedef struct Option {
 #define OPTION_FULL(fl, sc, lc, mv, h) _OPTION(__COUNTER__, fl, sc, lc, mv, h)
 #define OPTION(sc, lc, mv, h) OPTION_FULL(/* fl= */ 0, sc, lc, mv, h)
 #define OPTION_LONG(lc, mv, h) OPTION(/* sc= */ 0, lc, mv, h)
+#define OPTION_LONG_FLAGS(fl, lc, mv, h) OPTION_FULL(fl, /* sc= */ 0, lc, mv, h)
 #define OPTION_SHORT(sc, mv, h) OPTION(sc, /* lc= */ NULL, mv, h)
+#define OPTION_SHORT_FLAGS(fl, sc, mv, h) OPTION_FULL(fl, sc, /* lc= */ NULL, mv, h)
 
 #define OPTION_COMMON_HELP \
         OPTION('h', "help", NULL, "Show this help")