From: Michael Tremer Date: Sun, 15 Oct 2023 12:24:05 +0000 (+0000) Subject: cli: requires: Upgrade to the new parser X-Git-Tag: 0.9.30~1510 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1f81cbb2ccdd777cd01d193c950e2c5cb14895d4;p=pakfire.git cli: requires: Upgrade to the new parser Signed-off-by: Michael Tremer --- diff --git a/src/cli/lib/requires.c b/src/cli/lib/requires.c index 3a1aaf7c2..5b0703399 100644 --- a/src/cli/lib/requires.c +++ b/src/cli/lib/requires.c @@ -18,23 +18,71 @@ # # #############################################################################*/ +#include + #include +#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; } diff --git a/src/cli/lib/requires.h b/src/cli/lib/requires.h index c6c1b8f0b..97528640f 100644 --- a/src/cli/lib/requires.h +++ b/src/cli/lib/requires.h @@ -21,8 +21,6 @@ #ifndef PAKFIRE_CLI_REQUIRES_H #define PAKFIRE_CLI_REQUIRES_H -#include - -int cli_requires(struct pakfire* pakfire, int argc, char* argv[]); +int cli_requires(void* data, int argc, char* argv[]); #endif /* PAKFIRE_CLI_REQUIRES_H */ diff --git a/src/cli/pakfire-builder.c b/src/cli/pakfire-builder.c index d95636a26..7ada350f8 100644 --- a/src/cli/pakfire-builder.c +++ b/src/cli/pakfire-builder.c @@ -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 },