]> git.ipfire.org Git - pakfire.git/commitdiff
cli: Fix passing around command line arguments
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 29 Sep 2023 11:08:36 +0000 (11:08 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 29 Sep 2023 11:08:36 +0000 (11:08 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/cli/lib/command.c
src/cli/pakfire-builder.c
src/cli/pakfire.c

index 9c66426290b578fe148f22d34871cb9c833f1dd2..533a2634e914fd5fd3daefb0c2268396e45c5e3d 100644 (file)
@@ -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;
 
index 86fc4f50368a801bfb5a5ce006e82aa643675256..9d45afa27c420ad116b851992027d27a1f641f89 100644 (file)
@@ -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)
index 1851387447e364d0a53892d4293155b7ef13a823..ec64a72d53b2130240312f6f633ad3af10a646a6 100644 (file)
@@ -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)