From: Michael Tremer Date: Fri, 29 Sep 2023 11:08:36 +0000 (+0000) Subject: cli: Fix passing around command line arguments X-Git-Tag: 0.9.30~1608 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e01c5ad3cfdb944027ff27dc2a6ec9fca865d416;p=pakfire.git cli: Fix passing around command line arguments Signed-off-by: Michael Tremer --- diff --git a/src/cli/lib/command.c b/src/cli/lib/command.c index 9c6642629..533a2634e 100644 --- a/src/cli/lib/command.c +++ b/src/cli/lib/command.c @@ -38,12 +38,12 @@ static const struct command* command_find(const struct command* commands, const int command_dispatch(struct pakfire* pakfire, const struct command* commands, int argc, char* argv[]) { const struct command* command = NULL; - if (!argc) { + if (argc < 2) { fprintf(stderr, "Command required\n"); return -EINVAL; } - const char* verb = argv[0]; + const char* verb = argv[1]; // Find a matching command command = command_find(commands, verb); @@ -52,6 +52,10 @@ int command_dispatch(struct pakfire* pakfire, const struct command* commands, in return -EINVAL; } + // Consume the verb + argv++; + argc--; + // Reset optind optind = 1; diff --git a/src/cli/pakfire-builder.c b/src/cli/pakfire-builder.c index 86fc4f503..9d45afa27 100644 --- a/src/cli/pakfire-builder.c +++ b/src/cli/pakfire-builder.c @@ -269,7 +269,7 @@ int main(int argc, char* argv[]) { goto ERROR; // Run a command - r = cli_main(pakfire, argc - optind, argv + optind); + r = cli_main(pakfire, argc - optind + 1, argv + optind - 1); ERROR: if (pakfire) diff --git a/src/cli/pakfire.c b/src/cli/pakfire.c index 185138744..ec64a72d5 100644 --- a/src/cli/pakfire.c +++ b/src/cli/pakfire.c @@ -274,7 +274,7 @@ int main(int argc, char* argv[]) { cli_set_repo_enabled(pakfire, config.disable_repos[i], 0); // Run a command - r = cli_main(pakfire, argc - optind, argv + optind); + r = cli_main(pakfire, argc - optind + 1, argv + optind - 1); ERROR: if (f)