]> git.ipfire.org Git - pakfire.git/commitdiff
cli: Always set up an (even empty) parser so we can have docs
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 15 Oct 2023 11:06:38 +0000 (11:06 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 15 Oct 2023 11:06:38 +0000 (11:06 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/cli/lib/command.c

index 2a527f128d8f1e4c63832608335c77a11c9704ac..41d03cedb801b4931e6a4226443b056da215aa85 100644 (file)
@@ -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;