]> git.ipfire.org Git - pakfire.git/commitdiff
cli: requires: Upgrade to the new parser
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 15 Oct 2023 12:24:05 +0000 (12:24 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 15 Oct 2023 12:24:05 +0000 (12:24 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/cli/lib/requires.c
src/cli/lib/requires.h
src/cli/pakfire-builder.c

index 3a1aaf7c27e8b139084144406cdec2048ec83cd1..5b0703399203619356a1bd10b62e7f64934043e8 100644 (file)
 #                                                                             #
 #############################################################################*/
 
+#include <argp.h>
+
 #include <pakfire/pakfire.h>
 
+#include "command.h"
 #include "dump.h"
+#include "pakfire.h"
 #include "requires.h"
 
-int cli_requires(struct pakfire* pakfire, int argc, char* argv[]) {
+static const char* args_doc = "PATTERNS...";
+
+static const char* doc = "Search for packages that requires a certain pattern";
+
+#define MAX_PATTERNS 256
+
+struct config {
+       char* patterns[MAX_PATTERNS];
+       unsigned int num_patterns;
+};
+
+static error_t parse(int key, char* arg, void* data) {
+       struct config* config = data;
+
+       switch (key) {
+               case ARGP_KEY_ARG:
+                       if (config->num_patterns >= MAX_PATTERNS)
+                               return -ENOBUFS;
+
+                       config->patterns[config->num_patterns++] = arg;
+                       break;
+
+               default:
+                       return ARGP_ERR_UNKNOWN;
+       }
+
+       return 0;
+}
+
+int cli_requires(void* data, int argc, char* argv[]) {
+       struct pakfire* pakfire = NULL;
        struct pakfire_packagelist* list = NULL;
        int r;
 
+       struct cli_config* cli_config = data;
+
+       struct config config = {};
+
+       // Parse the command line
+       r = cli_parse(NULL, NULL, args_doc, doc, parse, argc, argv, &config);
+       if (r)
+               goto ERROR;
+
+       // Setup pakfire
+       r = cli_setup_pakfire(&pakfire, cli_config);
+       if (r)
+               goto ERROR;
+
        // Allocate a new packagelist
        r = pakfire_packagelist_create(&list, pakfire);
        if (r)
                goto ERROR;
 
        // Perform search
-       for (int i = 0; i < argc; i++) {
-               r = pakfire_whatrequires(pakfire, argv[i], 0, list);
+       for (unsigned int i = 0; i < config.num_patterns; i++) {
+               r = pakfire_whatrequires(pakfire, config.patterns[i], 0, list);
                if (r)
                        goto ERROR;
        }
@@ -45,6 +93,8 @@ int cli_requires(struct pakfire* pakfire, int argc, char* argv[]) {
 ERROR:
        if (list)
                pakfire_packagelist_unref(list);
+       if (pakfire)
+               pakfire_unref(pakfire);
 
        return r;
 }
index c6c1b8f0b4bb9161b3dd0072bc196327ab86bfa6..97528640f26ce33d11ec866bdf10b84b5a076952 100644 (file)
@@ -21,8 +21,6 @@
 #ifndef PAKFIRE_CLI_REQUIRES_H
 #define PAKFIRE_CLI_REQUIRES_H
 
-#include <pakfire/pakfire.h>
-
-int cli_requires(struct pakfire* pakfire, int argc, char* argv[]);
+int cli_requires(void* data, int argc, char* argv[]);
 
 #endif /* PAKFIRE_CLI_REQUIRES_H */
index d95636a26c3df842c80a2ea1311763794e4c11d7..7ada350f891373c736e2e56024a909475b152e49 100644 (file)
@@ -70,11 +70,11 @@ static const struct command commands[] = {
        { "image",    cli_image,   -1, -1, 0 },
        { "info",     cli_info,     1, -1, 0 },
        { "provides", cli_provides, 1, -1, 0 },
+       { "requires", cli_requires, 1, -1, 0 },
        { "search",   cli_search,   1, -1, 0 },
 #if 0
        { "repo",     0, cli_repo },
        { "repolist", 0, cli_repolist },
-       { "requires", 0, cli_requires },
        { "shell",    0, cli_shell },
 #endif
        { NULL },