# #
#############################################################################*/
+#include <argp.h>
+
#include <pakfire/pakfire.h>
+#include "command.h"
#include "dump.h"
+#include "pakfire.h"
#include "provides.h"
-int cli_provides(struct pakfire* pakfire, int argc, char* argv[]) {
+static const char* args_doc = "PATTERNS...";
+
+static const char* doc = "Search for packages that provide 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_provides(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_whatprovides(pakfire, argv[i], 0, list);
+ for (unsigned int i = 0; i < config.num_patterns; i++) {
+ r = pakfire_whatprovides(pakfire, config.patterns[i], 0, list);
if (r)
goto ERROR;
}
ERROR:
if (list)
pakfire_packagelist_unref(list);
+ if (pakfire)
+ pakfire_unref(pakfire);
return r;
}
#ifndef PAKFIRE_CLI_PROVIDES_H
#define PAKFIRE_CLI_PROVIDES_H
-#include <pakfire/pakfire.h>
-
-int cli_provides(struct pakfire* pakfire, int argc, char* argv[]);
+int cli_provides(void* data, int argc, char* argv[]);
#endif /* PAKFIRE_CLI_PROVIDES_H */
};
static const struct command commands[] = {
- { "build", cli_build, 1, -1, 0 },
- { "clean", cli_clean, 0, 0, 0 },
- { "dist", cli_dist, 1, -1, 0 },
- { "image", cli_image, -1, -1, 0 },
- { "info", cli_info, 1, -1, 0 },
- { "search", cli_search, 1, -1, 0 },
+ { "build", cli_build, 1, -1, 0 },
+ { "clean", cli_clean, 0, 0, 0 },
+ { "dist", cli_dist, 1, -1, 0 },
+ { "image", cli_image, -1, -1, 0 },
+ { "info", cli_info, 1, -1, 0 },
+ { "provides", cli_provides, 1, -1, 0 },
+ { "search", cli_search, 1, -1, 0 },
#if 0
- { "provides", 0, cli_provides },
{ "repo", 0, cli_repo },
{ "repolist", 0, cli_repolist },
{ "requires", 0, cli_requires },