]> Untitled Git - hvrtc.git/commitdiff
options: add "-h" option
authorHugo Villeneuve <hvilleneuve@dimonoff.com>
Mon, 17 Nov 2025 15:34:37 +0000 (10:34 -0500)
committerHugo Villeneuve <hvilleneuve@dimonoff.com>
Tue, 10 Mar 2026 19:33:52 +0000 (15:33 -0400)
Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
src/options.c

index 0dff2d781ba229a606ab9424f889cad92aed9a18..e0ee934d2b96a7ece69e3dd806e39a2b9a3992e6 100644 (file)
@@ -42,11 +42,22 @@ static const char str_doc[] = PACKAGE_NAME " -- " PACKAGE_DESCRIPTION;
 /* A description of the non-option arguments we accept. */
 static const char args_doc[] = "";
 
+/*
+ * Define integer key provided by the usage option to the option parser as a
+ * non-ASCII character, so that it doesn't display a short option.
+ */
+#define USAGE_KEY 0x123
+
 /* The options we understand. */
 static struct argp_option argp_options[] = {
        {"bsm",   'b', "value", OPTION_ARG_OPTIONAL, "Get/Set  Backup Switch Mode (BSM)", 0},
        {"dev",   'd', "path", 0, "RTC device path (optional)", 0},
        {"test",  't', 0,         0, "Test RTC", 0},
+       /*
+        * Add -h manually; OPTION_HIDDEN prevents it from appearing twice in --help.
+        * This must be listed after all other options, to prevent an empty line.
+        */
+       {NULL, 'h', 0, OPTION_HIDDEN, "Give this help list", -1},
        { 0 }
 };
 
@@ -101,6 +112,10 @@ parse_opt(int key, char *arg, struct argp_state *state)
        case 'd':
                options.rtc_path = arg;
                break;
+       case 'h':
+               /* ARGP_HELP_STD_HELP prints the full help and exits the program */
+               argp_state_help(state, state->out_stream, ARGP_HELP_STD_HELP);
+               break;
        case ARGP_KEY_ARG:
                /* We do not support any arguments after the options. */
                argp_usage(state);