From 43f73b9e8e102c82549712b81f086adda55a9043 Mon Sep 17 00:00:00 2001 From: "D. Bohdan" Date: Sat, 30 Sep 2023 10:22:34 +0000 Subject: [PATCH] feat(cli): handle `help` like other commands Keep `-h` and `--help` special-cased. --- cli.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cli.c b/cli.c index 34f095b..eebad63 100644 --- a/cli.c +++ b/cli.c @@ -407,7 +407,7 @@ bool str_prefix(const char* ref, const char* str) } typedef enum command { - ENCODE, DECODE, QUANTIZE, INFO, VERSION + ENCODE, DECODE, QUANTIZE, INFO, VERSION, HELP } command; int main(int argc, char** argv) @@ -427,8 +427,8 @@ int main(int argc, char** argv) return 1; } - if (str_prefix(HICOLOR_CLI_CMD_HELP, argv[1]) - || strcmp(argv[1], "-h") == 0 + /* The regular "help" command is handled later with other commands. */ + if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) { help(); return 0; @@ -457,6 +457,12 @@ int main(int argc, char** argv) min_pos_args = 0; max_pos_args = 0; opt_command = VERSION; + } else if (str_prefix(HICOLOR_CLI_CMD_HELP, argv[i])) { + allow_opts = false; + command_name = HICOLOR_CLI_CMD_HELP; + min_pos_args = 0; + max_pos_args = 0; + opt_command = HELP; } else { fprintf( stderr, @@ -539,5 +545,8 @@ int main(int argc, char** argv) case VERSION: version(); return 0; + case HELP: + help(); + return 0; } }