# #
#############################################################################*/
-#include <errno.h>
-#include <getopt.h>
-#include <stdio.h>
-#include <stdlib.h>
+#include <argp.h>
#include <pakfire/packagelist.h>
#include <pakfire/pakfire.h>
+#include "command.h"
#include "dump.h"
#include "info.h"
+#include "pakfire.h"
#include "transaction.h"
+static const char* args_doc = "info [OPTIONS...] PACKAGES...";
+
+static const char* doc = "Shows package information";
+
+#define MAX_PACKAGES 128
+
struct config {
int dump_flags;
+
+ // Packages
+ char* packages[MAX_PACKAGES];
+ unsigned int num_packages;
};
-static void help(void) {
- printf(
- "%s [OPTIONS...] info [OPTIONS...]\n\n"
- "Options:\n"
- " --devel Show more development information\n"
- " --filelist Show the filelist\n"
- " -h --help Show help\n",
- program_invocation_short_name
- );
-
- exit(0);
-}
+enum {
+ OPT_DEVEL = 1,
+ OPT_FILELIST = 2,
+};
-static int parse_argv(struct config* config, int argc, char* argv[]) {
- enum {
- ARG_DEVEL,
- ARG_FILELIST,
- };
+static struct argp_option options[] = {
+ { "devel", OPT_DEVEL, NULL, 0, "Show development information", 0 },
+ { "filelist", OPT_FILELIST, NULL, 0, "Show the filelist", 0 },
+ { NULL },
+};
- static const struct option options[] = {
- { "help", no_argument, NULL, 'h' },
- { "devel", no_argument, NULL, ARG_DEVEL },
- { "filelist", no_argument, NULL, ARG_FILELIST },
- { NULL },
- };
- int c;
+static error_t parse(int key, char* arg, void* data) {
+ struct config* config = data;
- for (;;) {
- c = getopt_long(argc, argv, "h", options, NULL);
- if (c < 0)
+ switch (key) {
+ case OPT_DEVEL:
+ config->dump_flags |= PAKFIRE_PKG_DUMP_LONG;
break;
- switch (c) {
- case 'h':
- help();
-
- case ARG_DEVEL:
- config->dump_flags |= PAKFIRE_PKG_DUMP_LONG;
- break;
+ case OPT_FILELIST:
+ config->dump_flags |= PAKFIRE_PKG_DUMP_FILELIST;
+ break;
- case ARG_FILELIST:
- config->dump_flags |= PAKFIRE_PKG_DUMP_FILELIST;
- break;
+ case ARGP_KEY_ARG:
+ if (config->num_packages >= MAX_PACKAGES)
+ return -ENOBUFS;
- case '?':
- return -EINVAL;
+ config->packages[config->num_packages++] = arg;
+ break;
- default:
- break;
- }
+ default:
+ return ARGP_ERR_UNKNOWN;
}
return 0;
}
-int cli_info(struct pakfire* pakfire, int argc, char* argv[]) {
+int cli_info(void* data, int argc, char* argv[]) {
+ struct pakfire* pakfire = NULL;
struct pakfire_packagelist* list = NULL;
struct config config = {
.dump_flags = 0,
};
int r;
- // Parse CLI options
- r = parse_argv(&config, argc, argv);
+ struct cli_config* cli_config = data;
+
+ // Parse the command line
+ r = cli_parse(options, NULL, args_doc, doc, parse, argc, argv, &config);
if (r)
- return 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);
goto ERROR;
// Perform search
- for (int i = 0; i < argc; i++) {
- r = pakfire_search(pakfire, argv[i], PAKFIRE_SEARCH_NAME_ONLY, list);
+ for (unsigned int i = 0; i < config.num_packages; i++) {
+ r = pakfire_search(pakfire, config.packages[i], PAKFIRE_SEARCH_NAME_ONLY, list);
if (r)
goto ERROR;
}
ERROR:
if (list)
pakfire_packagelist_unref(list);
+ if (pakfire)
+ pakfire_unref(pakfire);
return r;
}
{ "clean", cli_clean, 0, 0, 0 },
{ "dist", cli_dist, 1, -1, 0 },
{ "image", cli_image, -1, -1, 0 },
+ { "info", cli_info, 1, -1, 0 },
#if 0
- { "info", 0, cli_info },
{ "provides", 0, cli_provides },
{ "repo", 0, cli_repo },
{ "repolist", 0, cli_repolist },