options: redefine help to replace -? with -h
authorHugo Villeneuve <hvilleneuve@dimonoff.com>
Mon, 17 Nov 2025 15:34:37 +0000 (10:34 -0500)
committerHugo Villeneuve <hvilleneuve@dimonoff.com>
Mon, 17 Nov 2025 15:36:11 +0000 (10:36 -0500)
Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
src/options.c

index 4709c78..9345401 100644 (file)
@@ -49,6 +49,12 @@ static const char args_doc[] = "[EEPROM-PATH]";
        "    del   Delete TLV key\n"                            \
        "    list  List available TLV keys"
 
+/*
+ * 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[] = {
        {"addr",  'a', "num",  0, "I2C device address", 0},
@@ -58,6 +64,8 @@ static struct argp_option argp_options[] = {
        {"dev",   'd', "path", 0, "EEPROM device path (if not using I2C bus/addr)", 0},
        {"key",   'k', "key",  0, "TLV key", 0},
        {"value", 'v', "val",  0, "TLV value (string)", 0},
+       {"help",  'h', 0,  0, "Give this help list", -1},
+       {"usage", USAGE_KEY, 0,    0, "Give a short usage message", -1},
        { 0 }
 };
 
@@ -133,6 +141,14 @@ parse_opt(int key, char *arg, struct argp_state *state)
        case 'd':
                options.eeprom_path = arg;
                break;
+       case 'h':
+               argp_state_help(state, state->out_stream, ARGP_HELP_STD_HELP);
+               exit(0);
+               break;
+        case USAGE_KEY:
+               argp_state_help(state, state->out_stream, ARGP_HELP_USAGE | ARGP_HELP_EXIT_OK);
+               exit(0);
+               break;
        case 'k':
                decode_int(arg, state, &options.tlv_key);
                break;
@@ -168,7 +184,7 @@ int parse_command_line_options(int argc, char *argv[])
        options.tlv_value = NULL;
 
        /* Parse our arguments. */
-       rc = argp_parse(&argp, argc, argv, 0, 0, NULL);
+       rc = argp_parse(&argp, argc, argv, ARGP_NO_HELP, 0, NULL);
        if (rc != 0)
                log_fail("Failed to parse command line arguments\n");