From 67c07f9743e242bb6cbbdf3c58eaacb229547eda Mon Sep 17 00:00:00 2001 From: Hugo Villeneuve Date: Mon, 17 Nov 2025 10:34:37 -0500 Subject: [PATCH] options: add "-h" option Signed-off-by: Hugo Villeneuve --- src/options.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/options.c b/src/options.c index 0dff2d7..e0ee934 100644 --- a/src/options.c +++ b/src/options.c @@ -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); -- 2.47.3