# #
#############################################################################*/
-#include <pakfire/pakfire.h>
-
#include "command.h"
#include "image.h"
#include "image_create.h"
-int cli_image(struct pakfire* pakfire, int argc, char* argv[]) {
+int cli_image(void* data, int argc, char* argv[]) {
static const struct command commands[] = {
-#if 0
- { "create", 0, cli_image_create },
-#endif
+ { "create", cli_image_create, 2, 2, 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);
}
#ifndef PAKFIRE_CLI_IMAGE_H
#define PAKFIRE_CLI_IMAGE_H
-#include <pakfire/pakfire.h>
-
-int cli_image(struct pakfire* pakfire, int argc, char* argv[]);
+int cli_image(void* data, int argc, char* argv[]);
#endif /* PAKFIRE_CLI_IMAGE_H */
# #
#############################################################################*/
-#include <errno.h>
-#include <getopt.h>
-#include <stdlib.h>
+#include <argp.h>
#include <pakfire/build.h>
#include <pakfire/pakfire.h>
+#include "command.h"
#include "image_create.h"
+#include "pakfire.h"
-static void help(void) {
- printf(
- "%s [OPTIONS...] image create TYPE PATH...\n\n"
- "Options:\n"
- " -h --help Show help\n",
- program_invocation_short_name
- );
+struct config {
+ const char* type;
+ const char* path;
+};
- exit(0);
-}
+static const char* args_doc = "image create TYPE PATH";
-static int parse_argv(struct pakfire* pakfire, int argc, char* argv[]) {
- static const struct option options[] = {
- { "help", no_argument, NULL, 'h' },
- { NULL },
- };
- int c;
+static const char* doc = "Creates images";
- for (;;) {
- c = getopt_long(argc, argv, "h", options, NULL);
- if (c < 0)
- break;
+static error_t parse(int key, char* arg, void* data) {
+ struct config* config = data;
- switch (c) {
- case 'h':
- help();
+ switch (key) {
+ case ARGP_KEY_ARG:
+ if (!config->type)
+ config->type = arg;
- case '?':
- return -EINVAL;
+ else if (!config->path)
+ config->path = arg;
- default:
- break;
- }
+ break;
+
+ default:
+ return ARGP_ERR_UNKNOWN;
}
return 0;
}
-int cli_image_create(struct pakfire* pakfire, int argc, char* argv[]) {
+int cli_image_create(void* data, int argc, char* argv[]) {
+ struct pakfire* pakfire = NULL;
struct pakfire_build* build = NULL;
FILE* f = NULL;
int r;
- // Parse commandline
- r = parse_argv(pakfire, argc, argv);
- if (r)
- return r;
+ struct cli_config* cli_config = data;
- // XXX check arguments
+ struct config config = {
+ .type = NULL,
+ .path = NULL,
+ };
- f = fopen(argv[2], "w");
+ // Parse the command line
+ r = cli_parse(NULL, NULL, args_doc, doc, parse, argc, argv, &config);
+ if (r)
+ goto ERROR;
+
+ f = fopen(config.path, "w");
if (!f) {
- fprintf(stderr, "Could not open %s: %m\n", argv[2]);
+ fprintf(stderr, "Could not open %s: %m\n", config.path);
r = -errno;
goto ERROR;
}
+ // Setup pakfire
+ r = cli_setup_pakfire(&pakfire, cli_config);
+ if (r)
+ goto ERROR;
+
// Setup the build environment
r = pakfire_build_create(&build, pakfire, NULL, 0);
if (r)
goto ERROR;
// Create the image
- r = pakfire_build_mkimage(build, argv[1], f);
+ r = pakfire_build_mkimage(build, config.type, f);
if (r)
goto ERROR;
ERROR:
if (build)
pakfire_build_unref(build);
+ if (pakfire)
+ pakfire_unref(pakfire);
if (f)
fclose(f);
#ifndef PAKFIRE_CLI_IMAGE_CREATE_H
#define PAKFIRE_CLI_IMAGE_CREATE_H
-#include <pakfire/pakfire.h>
-
-int cli_image_create(struct pakfire* pakfire, int argc, char* argv[]);
+int cli_image_create(void* data, int argc, char* argv[]);
#endif /* PAKFIRE_CLI_IMAGE_CREATE_H */
};
static const struct command commands[] = {
- { "build", cli_build, 1, -1, 0 },
- { "clean", cli_clean, 0, 0, 0 },
- { "dist", cli_dist, 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 },
#if 0
- { "image", 0, cli_image },
{ "info", 0, cli_info },
{ "provides", 0, cli_provides },
{ "repo", 0, cli_repo },