From: Michael Tremer Date: Sun, 15 Oct 2023 11:06:38 +0000 (+0000) Subject: cli: Always set up an (even empty) parser so we can have docs X-Git-Tag: 0.9.30~1520 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=66367d632c6968e76bb7f66890853cfb2489d2d3;p=pakfire.git cli: Always set up an (even empty) parser so we can have docs Signed-off-by: Michael Tremer --- diff --git a/src/cli/lib/command.c b/src/cli/lib/command.c index 2a527f128..41d03cedb 100644 --- a/src/cli/lib/command.c +++ b/src/cli/lib/command.c @@ -96,8 +96,12 @@ static error_t __command_parse(int key, char* arg, struct argp_state* state) { int r; // Just call the parse function if we don't have any commands - if (!ctx->commands) + if (!ctx->commands) { + if (!ctx->parse) + return ARGP_ERR_UNKNOWN; + return ctx->parse(key, arg, ctx->data); + } switch (key) { // Show help if no arguments have been passed @@ -134,6 +138,9 @@ static error_t __command_parse(int key, char* arg, struct argp_state* state) { // Otherwise call the callback default: + if (!ctx->parse) + return ARGP_ERR_UNKNOWN; + return ctx->parse(key, arg, ctx->data); } @@ -163,7 +170,7 @@ int cli_parse(const struct argp_option* options, const struct command* commands, int arg_index = 0; // Parse command line options - r = argp_parse(options ? &parser : NULL, argc, argv, ARGP_IN_ORDER, &arg_index, &ctx); + r = argp_parse(&parser, argc, argv, ARGP_IN_ORDER, &arg_index, &ctx); if (r) return r;