From: Hugo Villeneuve Date: Mon, 17 Nov 2025 15:34:37 +0000 (-0500) Subject: options: redefine help to replace -? with -h X-Git-Url: http://gitweb.hugovil.com/?a=commitdiff_plain;h=90e3bb64b78476ad4407094e0f926339bae13ba1;p=mtlv.git options: redefine help to replace -? with -h Signed-off-by: Hugo Villeneuve --- diff --git a/src/options.c b/src/options.c index 4709c78..9345401 100644 --- a/src/options.c +++ b/src/options.c @@ -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");