From: Michael Tremer Date: Sun, 15 Oct 2023 11:31:03 +0000 (+0000) Subject: cli: dist: Upgrade to the new parser X-Git-Tag: 0.9.30~1515 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7014986e4cedd9918082d4d0cd0f7b117c6ea019;p=pakfire.git cli: dist: Upgrade to the new parser Signed-off-by: Michael Tremer --- diff --git a/src/cli/lib/dist.c b/src/cli/lib/dist.c index e4ade4cfd..ffb1ff5cc 100644 --- a/src/cli/lib/dist.c +++ b/src/cli/lib/dist.c @@ -18,83 +18,83 @@ # # #############################################################################*/ -#include -#include -#include -#include +#include #include "command.h" #include "dist.h" +#include "pakfire.h" #include #include -#define MAX_MAKEFILES 128 +static const char* args_doc = "dist MAKEFILES..."; + +static const char* doc = "Creates source packages from makefiles"; + +#define MAX_MAKEFILES 32 struct config { const char* resultdir; -}; -static void help(void) { - printf( - "%s [OPTIONS...] dist MAKEFILES...\n\n" - "Options:\n" - " -h --help Show help\n", - program_invocation_short_name - ); + // Makefiles + char* makefiles[MAX_MAKEFILES]; + unsigned int num_makefiles; +}; - exit(0); -} +static error_t parse(int key, char* arg, void* data) { + struct config* config = data; -static int parse_argv(int argc, char* argv[]) { - static const struct option options[] = { - { "help", no_argument, NULL, 'h' }, - { NULL }, - }; - int c; + switch (key) { + case ARGP_KEY_ARG: + if (config->num_makefiles >= MAX_MAKEFILES) + return -ENOBUFS; - for (;;) { - c = getopt_long(argc, argv, "h", options, NULL); - if (c < 0) + config->makefiles[config->num_makefiles++] = arg; break; - switch (c) { - case 'h': - help(); - - case '?': - return -EINVAL; - - default: - break; - } + default: + return ARGP_ERR_UNKNOWN; } return 0; } -int cli_dist(struct pakfire* pakfire, int argc, char* argv[]) { +int cli_dist(void* data, int argc, char* argv[]) { + struct pakfire* pakfire = NULL; struct config config = { .resultdir = NULL, }; char cwd[PATH_MAX]; int r; - // Parse commandline - r = parse_argv(argc, argv); + struct cli_config* cli_config = data; + + // Parse the command line + r = cli_parse(NULL, NULL, args_doc, doc, parse, argc, argv, &config); if (r) - return r; + goto ERROR; // Set result directory to PWD if (!config.resultdir) config.resultdir = getcwd(cwd, sizeof(cwd)); - // Run for all arguments - for (int i = 0; i < argc; i++) { + // Setup pakfire + r = cli_setup_pakfire(&pakfire, cli_config); + if (r) + goto ERROR; + + // Process all packages + for (unsigned int i = 0; i < config.num_makefiles; i++) { r = pakfire_dist(pakfire, argv[i], config.resultdir, NULL); - if (r) - break; + if (r) { + fprintf(stderr, "Could not dist %s\n", config.makefiles[i]); + goto ERROR; + } } +ERROR: + if (pakfire) + pakfire_unref(pakfire); + return r; } diff --git a/src/cli/lib/dist.h b/src/cli/lib/dist.h index 97f5583cb..ef940137f 100644 --- a/src/cli/lib/dist.h +++ b/src/cli/lib/dist.h @@ -21,8 +21,6 @@ #ifndef PAKFIRE_CLI_DIST_H #define PAKFIRE_CLI_DIST_H -#include - -int cli_dist(struct pakfire* pakfire, int argc, char* argv[]); +int cli_dist(void* data, int argc, char* argv[]); #endif /* PAKFIRE_CLI_DIST_H */ diff --git a/src/cli/pakfire-builder.c b/src/cli/pakfire-builder.c index 9c9350f89..11dbecf10 100644 --- a/src/cli/pakfire-builder.c +++ b/src/cli/pakfire-builder.c @@ -66,8 +66,8 @@ static struct argp_option options[] = { static const struct command commands[] = { { "build", cli_build, 1, -1, 0 }, { "clean", cli_clean, 0, 0, 0 }, + { "dist", cli_dist, 1, -1, 0 }, #if 0 - { "dist", 0, cli_dist }, { "image", 0, cli_image }, { "info", 0, cli_info }, { "provides", 0, cli_provides },