# #
#############################################################################*/
-#include <pakfire/pakfire.h>
-
#include "command.h"
#include "repo.h"
#include "repo_compose.h"
-int cli_repo(struct pakfire* pakfire, int argc, char* argv[]) {
+int cli_repo(void* data, int argc, char* argv[]) {
static const struct command commands[] = {
-#if 0
- { "compose", 0, cli_repo_compose },
-#endif
+ { "compose", cli_repo_compose, 1, -1, 0 },
{ NULL },
};
- return 0;
-
-#if 0
- return command_dispatch(pakfire, commands, 1, argc, argv);
-#endif
+ return cli_parse(NULL, commands, NULL, NULL, NULL, argc, argv, data);
}
# #
#############################################################################*/
-#include <errno.h>
-#include <getopt.h>
-#include <stdlib.h>
+#include <argp.h>
+#include <pakfire/key.h>
#include <pakfire/pakfire.h>
+#include "command.h"
#include "repo_compose.h"
+#include "pakfire.h"
+
+static const char* args_doc = "[OPTIONS...] PATH PACKAGES...";
+
+static const char* doc = "Create a new repository";
+
+#define MAX_PACKAGES 1024
struct config {
const char* path;
- char** files;
- struct pakfire_key* key;
+ const char* key;
+
+ char* packages[MAX_PACKAGES];
+ unsigned int num_packages;
+};
+
+enum {
+ OPT_KEY = 1,
+};
+
+static struct argp_option options[] = {
+ { "key", OPT_KEY, "KEY", 0, "Use this key to sign the repository", 0 },
+ { NULL },
};
-static void help(void) {
- printf(
- "%s [OPTIONS...] repo compose [OPTIONS...] PACKAGE...\n\n"
- "Options:\n"
- " --key PATH The key to sign the repository with\n"
- " -h --help Show help\n",
- program_invocation_short_name
- );
+static error_t parse(int key, char* arg, void* data) {
+ struct config* config = data;
+
+ switch (key) {
+ case OPT_KEY:
+ config->key = arg;
+ break;
- exit(0);
+ case ARGP_KEY_ARG:
+ if (!config->path)
+ config->path = arg;
+
+ else if (config->num_packages >= MAX_PACKAGES)
+ return -ENOBUFS;
+
+ else
+ config->packages[config->num_packages++] = arg;
+ break;
+
+ default:
+ return ARGP_ERR_UNKNOWN;
+ }
+
+ return 0;
}
static int cli_import_key(struct pakfire_key** key,
return r;
}
-static int parse_argv(struct pakfire* pakfire, struct config* config,
- int argc, char* argv[]) {
- enum {
- ARG_KEY,
- };
+int cli_repo_compose(void* data, int argc, char* argv[]) {
+ struct pakfire* pakfire = NULL;
+ struct pakfire_key* key = NULL;
int r;
- static const struct option options[] = {
- { "key", required_argument, NULL, ARG_KEY },
- { "help", no_argument, NULL, 'h' },
- { NULL },
- };
- int c;
+ struct cli_config* cli_config = data;
- for (;;) {
- c = getopt_long(argc, argv, "h", options, NULL);
- if (c < 0)
- break;
-
- switch (c) {
- case 'h':
- help();
-
- case ARG_KEY:
- r = cli_import_key(&config->key, pakfire, optarg);
- if (r)
- return r;
- break;
-
- case '?':
- return -EINVAL;
-
- default:
- break;
- }
- }
-
- return 0;
-}
-
-
-int cli_repo_compose(struct pakfire* pakfire, int argc, char* argv[]) {
struct config config = {
.path = NULL,
.key = NULL,
};
- int r;
- // Parse commandline
- r = parse_argv(pakfire, &config, argc, argv);
+ // Parse the command line
+ r = cli_parse(options, NULL, args_doc, doc, parse, argc, argv, &config);
if (r)
- return r;
+ goto ERROR;
- // XXX check if we have enough arguments
+ // Setup pakfire
+ r = cli_setup_pakfire(&pakfire, cli_config);
+ if (r)
+ goto ERROR;
- // Set path
- config.path = argv[optind++]; argc--;
- config.files = argv + optind;
+ // Read the key (if any)
+ if (config.key) {
+ r = cli_import_key(&key, pakfire, config.key);
+ if (r)
+ goto ERROR;
+ }
+
+ // Write the repository
+ r = pakfire_repo_compose(pakfire, config.path, key, (const char**)config.packages);
- return pakfire_repo_compose(pakfire, config.path, config.key, (const char**)config.files);
+ERROR:
+ if (key)
+ pakfire_key_unref(key);
+ if (pakfire)
+ pakfire_unref(pakfire);
+
+ return r;
}
{ "image", cli_image, -1, -1, 0 },
{ "info", cli_info, 1, -1, 0 },
{ "provides", cli_provides, 1, -1, 0 },
+ { "repo", cli_repo, -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 },
{ "shell", 0, cli_shell },
#endif