From 343d9736583d9b4c2c5401ec8b2567ddf2e51871 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sun, 5 Jan 2025 15:25:34 +0000 Subject: [PATCH] CLI: Rename config to args We use the name config for too many things it was not very clear where things were coming from. Hence this change. Signed-off-by: Michael Tremer --- src/cli/lib/build.c | 62 +++++++++++++++++------------------ src/cli/lib/clean.c | 5 ++- src/cli/lib/client-build.c | 51 ++++++++++++++-------------- src/cli/lib/dist.c | 29 ++++++++-------- src/cli/lib/image_create.c | 43 ++++++++++++------------ src/cli/lib/info.c | 31 ++++++++---------- src/cli/lib/install.c | 33 +++++++++---------- src/cli/lib/lint.c | 22 ++++++------- src/cli/lib/pakfire.c | 24 +++++++------- src/cli/lib/pakfire.h | 4 +-- src/cli/lib/provides.c | 24 +++++++------- src/cli/lib/remove.c | 27 ++++++++------- src/cli/lib/repo_compose.c | 33 ++++++++----------- src/cli/lib/repo_create.c | 25 +++++++------- src/cli/lib/repo_delete.c | 23 +++++++------ src/cli/lib/repo_list.c | 19 +++++------ src/cli/lib/repo_show.c | 23 +++++++------ src/cli/lib/repolist.c | 5 ++- src/cli/lib/requires.c | 24 +++++++------- src/cli/lib/search.c | 24 +++++++------- src/cli/lib/shell.c | 47 +++++++++++++------------- src/cli/lib/snapshot_update.c | 5 ++- src/cli/lib/sync.c | 21 ++++++------ src/cli/lib/update.c | 37 ++++++++++----------- src/cli/lib/upload_create.c | 23 +++++++------ src/cli/lib/upload_delete.c | 21 ++++++------ src/cli/lib/upload_list.c | 5 ++- src/cli/pakfire-builder.c | 20 +++++------ src/cli/pakfire-client.c | 10 +++--- src/cli/pakfire.c | 24 +++++++------- 30 files changed, 354 insertions(+), 390 deletions(-) diff --git a/src/cli/lib/build.c b/src/cli/lib/build.c index 343d73fb1..274c79300 100644 --- a/src/cli/lib/build.c +++ b/src/cli/lib/build.c @@ -34,7 +34,7 @@ #define MAX_MAKEFILES 32 -struct config { +struct cli_local_args { const char* distro; const char* id; const char* target; @@ -72,42 +72,42 @@ static struct argp_option options[] = { }; static error_t parse(int key, char* arg, struct argp_state* state, void* data) { - struct config* config = data; + struct cli_local_args* args = data; switch (key) { case OPT_DISTRO: - config->distro = arg; + args->distro = arg; break; case OPT_DISABLE_CCACHE: - config->flags &= ~BUILD_ENABLE_CCACHE; + args->flags &= ~BUILD_ENABLE_CCACHE; break; case OPT_DISABLE_SNAPSHOT: - config->flags &= ~BUILD_ENABLE_SNAPSHOT; + args->flags &= ~BUILD_ENABLE_SNAPSHOT; break; case OPT_DISABLE_TESTS: - config->flags &= ~BUILD_ENABLE_TESTS; + args->flags &= ~BUILD_ENABLE_TESTS; break; case OPT_ID: - config->id = arg; + args->id = arg; break; case OPT_NON_INTERACTIVE: - config->flags &= ~BUILD_INTERACTIVE; + args->flags &= ~BUILD_INTERACTIVE; break; case OPT_TARGET: - config->target = arg; + args->target = arg; break; case ARGP_KEY_ARG: - if (config->num_makefiles >= MAX_MAKEFILES) + if (args->num_makefiles >= MAX_MAKEFILES) return -ENOBUFS; - config->makefiles[config->num_makefiles++] = arg; + args->makefiles[args->num_makefiles++] = arg; break; default: @@ -154,10 +154,8 @@ static void log_callback(void* data, int priority, const char* file, int line, } int cli_build(void* data, int argc, char* argv[]) { - struct cli_config* cli_config = data; - struct pakfire_build* build = NULL; - struct pakfire_config* c = NULL; - struct config config = { + struct cli_global_args* global_args = data; + struct cli_local_args local_args = { .distro = NULL, .id = NULL, .target = NULL, @@ -167,60 +165,62 @@ int cli_build(void* data, int argc, char* argv[]) { BUILD_ENABLE_SNAPSHOT | BUILD_ENABLE_TESTS, }; + struct pakfire_config* config = NULL; + struct pakfire_build* build = NULL; int build_flags = 0; int r; // Parse the command line - r = cli_parse(options, NULL, NULL, NULL, parse, 0, argc, argv, &config); + r = cli_parse(options, NULL, NULL, NULL, parse, 0, argc, argv, &local_args); if (r) goto ERROR; // Replace the logger - pakfire_ctx_set_log_callback(cli_config->ctx, log_callback, NULL); + pakfire_ctx_set_log_callback(global_args->ctx, log_callback, NULL); // Use the snapshot? - if (config.flags & BUILD_ENABLE_SNAPSHOT) + if (local_args.flags & BUILD_ENABLE_SNAPSHOT) build_flags |= PAKFIRE_BUILD_ENABLE_SNAPSHOT; // Is the build interactive? - if (config.flags & BUILD_INTERACTIVE) + if (local_args.flags & BUILD_INTERACTIVE) build_flags |= PAKFIRE_BUILD_INTERACTIVE; // Enable ccache? - if (!(config.flags & BUILD_ENABLE_CCACHE)) + if (!(local_args.flags & BUILD_ENABLE_CCACHE)) build_flags |= PAKFIRE_BUILD_DISABLE_CCACHE; // Enable tests? - if (!(config.flags & BUILD_ENABLE_TESTS)) + if (!(local_args.flags & BUILD_ENABLE_TESTS)) build_flags |= PAKFIRE_BUILD_DISABLE_TESTS; // Read distro configuration - r = cli_read_distro_config(&c, cli_config->ctx, config.distro); + r = cli_read_distro_config(&config, global_args->ctx, local_args.distro); if (r < 0) goto ERROR; // Setup the build environment - r = pakfire_build_create(&build, cli_config->ctx, c, cli_config->arch, config.id, build_flags); + r = pakfire_build_create(&build, global_args->ctx, config, global_args->arch, local_args.id, build_flags); if (r) { fprintf(stderr, "Could not setup the build environment: %m\n"); goto ERROR; } // Set target - if (config.target) { - r = pakfire_build_set_target(build, config.target); + if (local_args.target) { + r = pakfire_build_set_target(build, local_args.target); if (r) { - fprintf(stderr, "Could not set target directory %s: %m\n", config.target); + fprintf(stderr, "Could not set target directory %s: %m\n", local_args.target); goto ERROR; } } // Process all packages - for (unsigned int i = 0; i < config.num_makefiles; i++) { + for (unsigned int i = 0; i < local_args.num_makefiles; i++) { // Run the build - r = pakfire_build_exec(build, config.makefiles[i]); + r = pakfire_build_exec(build, local_args.makefiles[i]); if (r) { - fprintf(stderr, "Could not build %s\n", config.makefiles[i]); + fprintf(stderr, "Could not build %s\n", local_args.makefiles[i]); goto ERROR; } } @@ -228,8 +228,8 @@ int cli_build(void* data, int argc, char* argv[]) { ERROR: if (build) pakfire_build_unref(build); - if (c) - pakfire_config_unref(c); + if (config) + pakfire_config_unref(config); return r; } diff --git a/src/cli/lib/clean.c b/src/cli/lib/clean.c index 232ae6be4..f95d33fdd 100644 --- a/src/cli/lib/clean.c +++ b/src/cli/lib/clean.c @@ -28,18 +28,17 @@ static const char* doc = "Removes any temporary files required or left over by" " previous builds."; int cli_clean(void* data, int argc, char* argv[]) { + struct cli_global_args* global_args = data; struct pakfire* pakfire = NULL; int r; - struct cli_config* config = data; - // Parse the command line r = cli_parse(NULL, NULL, NULL, doc, NULL, 0, argc, argv, NULL); if (r) goto ERROR; // Setup Pakfire - r = cli_setup_pakfire(&pakfire, config); + r = cli_setup_pakfire(&pakfire, global_args); if (r) goto ERROR; diff --git a/src/cli/lib/client-build.c b/src/cli/lib/client-build.c index e76b72075..beb92c32e 100644 --- a/src/cli/lib/client-build.c +++ b/src/cli/lib/client-build.c @@ -35,7 +35,7 @@ static const char* doc = "Build packages remotely"; #define MAX_PACKAGES 32 #define MAX_MAKEFILES 32 -struct config { +struct cli_local_args { const char* repo; int flags; @@ -65,29 +65,29 @@ static struct argp_option options[] = { }; static error_t parse(int key, char* arg, struct argp_state* state, void* data) { - struct config* config = data; + struct cli_local_args* args = data; switch (key) { case OPT_ARCH: - if (config->num_arches >= MAX_ARCHES) + if (args->num_arches >= MAX_ARCHES) return -ENOBUFS; - config->arches[config->num_arches++] = arg; + args->arches[args->num_arches++] = arg; break; case OPT_DISABLE_TESTS: - config->flags |= PAKFIRE_BUILD_DISABLE_TESTS; + args->flags |= PAKFIRE_BUILD_DISABLE_TESTS; break; case OPT_REPO: - config->repo = arg; + args->repo = arg; break; case ARGP_KEY_ARG: - if (config->num_packages >= MAX_PACKAGES) + if (args->num_packages >= MAX_PACKAGES) return -ENOBUFS; - config->packages[config->num_packages++] = arg; + args->packages[args->num_packages++] = arg; break; default: @@ -98,55 +98,54 @@ static error_t parse(int key, char* arg, struct argp_state* state, void* data) { } int cli_client_build(void* data, int argc, char* argv[]) { + struct cli_global_args* global_args = data; + struct cli_local_args local_args = {}; struct pakfire_buildservice* service = NULL; - struct config config = {}; char* upload = NULL; int r; - struct cli_config* cli_config = data; - // Parse the command line - r = cli_parse(options, NULL, args_doc, doc, parse, 0, argc, argv, &config); + r = cli_parse(options, NULL, args_doc, doc, parse, 0, argc, argv, &local_args); if (r) goto ERROR; // Connect to the build service - r = pakfire_buildservice_create(&service, cli_config->ctx); + r = pakfire_buildservice_create(&service, global_args->ctx); if (r) goto ERROR; // Upload all packages - for (unsigned int i = 0; i < config.num_packages; i++) { - r = pakfire_buildservice_upload(service, config.packages[i], NULL, &upload); + for (unsigned int i = 0; i < local_args.num_packages; i++) { + r = pakfire_buildservice_upload(service, local_args.packages[i], NULL, &upload); if (r) goto ERROR; // Store the upload ID - config.uploads[config.num_uploads++] = upload; + local_args.uploads[local_args.num_uploads++] = upload; } // No uploads - if (!config.num_uploads) + if (!local_args.num_uploads) goto ERROR; // Build all the things - for (unsigned int i = 0; i < config.num_uploads; i++) { - r = pakfire_buildservice_build(service, config.uploads[i], config.repo, - config.arches, config.flags); + for (unsigned int i = 0; i < local_args.num_uploads; i++) { + r = pakfire_buildservice_build(service, local_args.uploads[i], local_args.repo, + local_args.arches, local_args.flags); if (r) goto ERROR; // Free the upload - free(config.uploads[i]); - config.uploads[i] = NULL; + free(local_args.uploads[i]); + local_args.uploads[i] = NULL; } ERROR: // Delete & free all uploads that could not be processed - for (unsigned int i = 0; i < config.num_uploads; i++) { - if (config.uploads[i]) { - pakfire_buildservice_delete_upload(service, config.uploads[i]); - free(config.uploads[i]); + for (unsigned int i = 0; i < local_args.num_uploads; i++) { + if (local_args.uploads[i]) { + pakfire_buildservice_delete_upload(service, local_args.uploads[i]); + free(local_args.uploads[i]); } } if (service) diff --git a/src/cli/lib/dist.c b/src/cli/lib/dist.c index 4350354e0..684d4349d 100644 --- a/src/cli/lib/dist.c +++ b/src/cli/lib/dist.c @@ -33,7 +33,7 @@ static const char* doc = "Creates source packages from makefiles"; #define MAX_MAKEFILES 32 -struct config { +struct cli_local_args { const char* resultdir; // Makefiles @@ -42,14 +42,14 @@ struct config { }; static error_t parse(int key, char* arg, struct argp_state* state, void* data) { - struct config* config = data; + struct cli_local_args* args = data; switch (key) { case ARGP_KEY_ARG: - if (config->num_makefiles >= MAX_MAKEFILES) + if (args->num_makefiles >= MAX_MAKEFILES) return -ENOBUFS; - config->makefiles[config->num_makefiles++] = arg; + args->makefiles[args->num_makefiles++] = arg; break; default: @@ -60,34 +60,31 @@ static error_t parse(int key, char* arg, struct argp_state* state, void* data) { } int cli_dist(void* data, int argc, char* argv[]) { + struct cli_global_args* global_args = data; + struct cli_local_args local_args = {}; struct pakfire* pakfire = NULL; - struct config config = { - .resultdir = NULL, - }; char cwd[PATH_MAX]; int r; - struct cli_config* cli_config = data; - // Parse the command line - r = cli_parse(NULL, NULL, args_doc, doc, parse, 0, argc, argv, &config); + r = cli_parse(NULL, NULL, args_doc, doc, parse, 0, argc, argv, &local_args); if (r) goto ERROR; // Set result directory to PWD - if (!config.resultdir) - config.resultdir = getcwd(cwd, sizeof(cwd)); + if (!local_args.resultdir) + local_args.resultdir = getcwd(cwd, sizeof(cwd)); // Setup pakfire - r = cli_setup_pakfire(&pakfire, cli_config); + r = cli_setup_pakfire(&pakfire, global_args); if (r) goto ERROR; // Process all packages - for (unsigned int i = 0; i < config.num_makefiles; i++) { - r = pakfire_dist(pakfire, config.makefiles[i], config.resultdir, NULL); + for (unsigned int i = 0; i < local_args.num_makefiles; i++) { + r = pakfire_dist(pakfire, local_args.makefiles[i], local_args.resultdir, NULL); if (r) { - fprintf(stderr, "Could not dist %s\n", config.makefiles[i]); + fprintf(stderr, "Could not dist %s\n", local_args.makefiles[i]); goto ERROR; } } diff --git a/src/cli/lib/image_create.c b/src/cli/lib/image_create.c index 202bd3668..d79292c14 100644 --- a/src/cli/lib/image_create.c +++ b/src/cli/lib/image_create.c @@ -28,7 +28,7 @@ #include "image_create.h" #include "pakfire.h" -struct config { +struct cli_local_args { const char* distro; const char* type; const char* path; @@ -48,19 +48,19 @@ static struct argp_option options[] = { }; static error_t parse(int key, char* arg, struct argp_state* state, void* data) { - struct config* config = data; + struct cli_local_args* args = data; switch (key) { case OPT_DISTRO: - config->distro = arg; + args->distro = arg; break; case ARGP_KEY_ARG: - if (!config->type) - config->type = arg; + if (!args->type) + args->type = arg; - else if (!config->path) - config->path = arg; + else if (!args->path) + args->path = arg; break; @@ -72,49 +72,48 @@ static error_t parse(int key, char* arg, struct argp_state* state, void* data) { } int cli_image_create(void* data, int argc, char* argv[]) { - struct cli_config* cli_config = data; - struct pakfire_config* c = NULL; - struct pakfire_build* build = NULL; - FILE* f = NULL; - int r; - - struct config config = { + struct cli_global_args* global_args = data; + struct cli_local_args local_args = { .type = NULL, .path = NULL, }; + struct pakfire_config* config = NULL; + struct pakfire_build* build = NULL; + FILE* f = NULL; + int r; // Parse the command line - r = cli_parse(options, NULL, args_doc, doc, parse, 0, argc, argv, &config); + r = cli_parse(options, NULL, args_doc, doc, parse, 0, argc, argv, &local_args); if (r) goto ERROR; // Read the distro configuration - r = cli_read_distro_config(&c, cli_config->ctx, config.distro); + r = cli_read_distro_config(&config, global_args->ctx, local_args.distro); if (r < 0) goto ERROR; - f = fopen(config.path, "w"); + f = fopen(local_args.path, "w"); if (!f) { - fprintf(stderr, "Could not open %s: %m\n", config.path); + fprintf(stderr, "Could not open %s: %m\n", local_args.path); r = -errno; goto ERROR; } // Setup the build environment - r = pakfire_build_create(&build, cli_config->ctx, c, cli_config->arch, NULL, 0); + r = pakfire_build_create(&build, global_args->ctx, config, global_args->arch, NULL, 0); if (r) goto ERROR; // Create the image - r = pakfire_build_mkimage(build, config.type, f); + r = pakfire_build_mkimage(build, local_args.type, f); if (r) goto ERROR; ERROR: if (build) pakfire_build_unref(build); - if (c) - pakfire_config_unref(c); + if (config) + pakfire_config_unref(config); if (f) fclose(f); diff --git a/src/cli/lib/info.c b/src/cli/lib/info.c index 311919a1a..fc578cd30 100644 --- a/src/cli/lib/info.c +++ b/src/cli/lib/info.c @@ -35,7 +35,7 @@ static const char* doc = "Shows package information"; #define MAX_PACKAGES 128 -struct config { +struct cli_local_args { int dump_flags; // Packages @@ -55,22 +55,22 @@ static struct argp_option options[] = { }; static error_t parse(int key, char* arg, struct argp_state* state, void* data) { - struct config* config = data; + struct cli_local_args* args = data; switch (key) { case OPT_DEVEL: - config->dump_flags |= PAKFIRE_PKG_DUMP_LONG; + args->dump_flags |= PAKFIRE_PKG_DUMP_LONG; break; case OPT_FILELIST: - config->dump_flags |= PAKFIRE_PKG_DUMP_FILELIST; + args->dump_flags |= PAKFIRE_PKG_DUMP_FILELIST; break; case ARGP_KEY_ARG: - if (config->num_packages >= MAX_PACKAGES) + if (args->num_packages >= MAX_PACKAGES) return -ENOBUFS; - config->packages[config->num_packages++] = arg; + args->packages[args->num_packages++] = arg; break; default: @@ -81,39 +81,36 @@ static error_t parse(int key, char* arg, struct argp_state* state, void* data) { } int cli_info(void* data, int argc, char* argv[]) { + struct cli_global_args* global_args = data; + struct cli_local_args local_args = {}; struct pakfire* pakfire = NULL; struct pakfire_packagelist* list = NULL; - struct config config = { - .dump_flags = 0, - }; int r; - struct cli_config* cli_config = data; - // Parse the command line - r = cli_parse(options, NULL, args_doc, doc, parse, 0, argc, argv, &config); + r = cli_parse(options, NULL, args_doc, doc, parse, 0, argc, argv, &local_args); if (r) goto ERROR; // Setup Pakfire - r = cli_setup_pakfire(&pakfire, cli_config); + r = cli_setup_pakfire(&pakfire, global_args); if (r) goto ERROR; // Allocate a new packagelist - r = pakfire_packagelist_create(&list, cli_config->ctx); + r = pakfire_packagelist_create(&list, global_args->ctx); if (r) goto ERROR; // Perform search - for (unsigned int i = 0; i < config.num_packages; i++) { - r = pakfire_search(pakfire, config.packages[i], PAKFIRE_SEARCH_NAME_ONLY, list); + for (unsigned int i = 0; i < local_args.num_packages; i++) { + r = pakfire_search(pakfire, local_args.packages[i], PAKFIRE_SEARCH_NAME_ONLY, list); if (r) goto ERROR; } // Dump the packagelist - r = cli_dump_packagelist(list, config.dump_flags); + r = cli_dump_packagelist(list, local_args.dump_flags); ERROR: if (list) diff --git a/src/cli/lib/install.c b/src/cli/lib/install.c index 2502a31c1..eabe63559 100644 --- a/src/cli/lib/install.c +++ b/src/cli/lib/install.c @@ -33,7 +33,7 @@ static const char* doc = "Install packages"; #define MAX_PACKAGES 128 -struct config { +struct cli_local_args { int transaction_flags; int job_flags; @@ -58,30 +58,30 @@ static struct argp_option options[] = { }; static error_t parse(int key, char* arg, struct argp_state* state, void* data) { - struct config* config = data; + struct cli_local_args* args = data; switch (key) { case OPT_BEST: - config->job_flags |= PAKFIRE_JOB_BEST; + args->job_flags |= PAKFIRE_JOB_BEST; break; case OPT_ALLOW_DOWNGRADE: - config->transaction_flags |= PAKFIRE_TRANSACTION_ALLOW_DOWNGRADE; + args->transaction_flags |= PAKFIRE_TRANSACTION_ALLOW_DOWNGRADE; break; case OPT_ALLOW_UNINSTALL: - config->transaction_flags |= PAKFIRE_TRANSACTION_ALLOW_UNINSTALL; + args->transaction_flags |= PAKFIRE_TRANSACTION_ALLOW_UNINSTALL; break; case OPT_WITHOUT_RECOMMENDED: - config->transaction_flags |= PAKFIRE_TRANSACTION_WITHOUT_RECOMMENDED; + args->transaction_flags |= PAKFIRE_TRANSACTION_WITHOUT_RECOMMENDED; break; case ARGP_KEY_ARG: - if (config->num_packages >= MAX_PACKAGES) + if (args->num_packages >= MAX_PACKAGES) return -ENOBUFS; - config->packages[config->num_packages++] = arg; + args->packages[args->num_packages++] = arg; break; default: @@ -92,13 +92,13 @@ static error_t parse(int key, char* arg, struct argp_state* state, void* data) { } static int __cli_install(struct pakfire_transaction* transaction, int argc, char* argv[], void* data) { - struct config* config = (struct config*)data; + struct cli_local_args* args = data; int r; // Add the remaining command line options as packages - for (unsigned int i = 0; i < config->num_packages; i++) { + for (unsigned int i = 0; i < args->num_packages; i++) { r = pakfire_transaction_request(transaction, - PAKFIRE_JOB_INSTALL, config->packages[i], config->job_flags); + PAKFIRE_JOB_INSTALL, args->packages[i], args->job_flags); if (r) { fprintf(stderr, "Could not find '%s': %m\n", argv[i]); return r; @@ -109,23 +109,22 @@ static int __cli_install(struct pakfire_transaction* transaction, int argc, char } int cli_install(void* data, int argc, char* argv[]) { + struct cli_global_args* global_args = data; + struct cli_local_args local_args = {}; struct pakfire* pakfire = NULL; - struct config config = {}; int r; - struct cli_config* cli_config = data; - // Parse the command line - r = cli_parse(options, NULL, args_doc, doc, parse, 0, argc, argv, &config); + r = cli_parse(options, NULL, args_doc, doc, parse, 0, argc, argv, &local_args); if (r) goto ERROR; // Setup Pakfire - r = cli_setup_pakfire(&pakfire, cli_config); + r = cli_setup_pakfire(&pakfire, global_args); if (r) goto ERROR; - r = cli_transaction(pakfire, argc, argv, config.transaction_flags, __cli_install, &config); + r = cli_transaction(pakfire, argc, argv, local_args.transaction_flags, __cli_install, &local_args); ERROR: if (pakfire) diff --git a/src/cli/lib/lint.c b/src/cli/lib/lint.c index bfa614bdc..03b211e49 100644 --- a/src/cli/lib/lint.c +++ b/src/cli/lib/lint.c @@ -36,21 +36,21 @@ static const char* doc = "Lint archives"; #define MAX_ARCHIVES 128 -struct config { +struct cli_local_args { // Archives char* archives[MAX_ARCHIVES]; unsigned int num_archives; }; static error_t parse(int key, char* arg, struct argp_state* state, void* data) { - struct config* config = data; + struct cli_local_args* args = data; switch (key) { case ARGP_KEY_ARG: - if (config->num_archives >= MAX_ARCHIVES) + if (args->num_archives >= MAX_ARCHIVES) return -ENOBUFS; - config->archives[config->num_archives++] = arg; + args->archives[args->num_archives++] = arg; break; default: @@ -111,26 +111,24 @@ ERROR: } int cli_lint(void* data, int argc, char* argv[]) { + struct cli_global_args* global_args = data; + struct cli_local_args local_args = {}; struct pakfire* pakfire = 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, 0, argc, argv, &config); + r = cli_parse(NULL, NULL, args_doc, doc, parse, 0, argc, argv, &local_args); if (r) goto ERROR; // Setup Pakfire - r = cli_setup_pakfire(&pakfire, cli_config); + r = cli_setup_pakfire(&pakfire, global_args); if (r) goto ERROR; // Lint all archives - for (unsigned int i = 0; i < config.num_archives; i++) { - r = do_lint(pakfire, config.archives[i]); + for (unsigned int i = 0; i < local_args.num_archives; i++) { + r = do_lint(pakfire, local_args.archives[i]); if (r < 0) goto ERROR; } diff --git a/src/cli/lib/pakfire.c b/src/cli/lib/pakfire.c index 32e824d34..fccef1c14 100644 --- a/src/cli/lib/pakfire.c +++ b/src/cli/lib/pakfire.c @@ -43,45 +43,45 @@ static void cli_set_repo_enabled(struct pakfire* pakfire, const char* name, int pakfire_repo_unref(repo); } -int cli_setup_pakfire(struct pakfire** pakfire, struct cli_config* config) { - struct pakfire_config* c = NULL; +int cli_setup_pakfire(struct pakfire** pakfire, struct cli_global_args* args) { + struct pakfire_config* config = NULL; struct pakfire* p = NULL; FILE* f = NULL; int r; // Create a new config object - r = pakfire_config_create(&c); + r = pakfire_config_create(&config); if (r < 0) goto ERROR; // Open the regular configuration - if (config->config) { - r = pakfire_config_read_path(c, config->config); + if (args->config) { + r = pakfire_config_read_path(config, args->config); if (r < 0) goto ERROR; } // Initialize Pakfire - r = pakfire_create(&p, config->ctx, c, config->root, config->arch, config->flags); + r = pakfire_create(&p, args->ctx, config, args->root, args->arch, args->flags); if (r < 0) { fprintf(stderr, "Could not initialize Pakfire: %s\n", strerror(-r)); goto ERROR; } // Enable repositories - for (unsigned int i = 0; i < config->num_enable_repos; i++) - cli_set_repo_enabled(p, config->enable_repos[i], 1); + for (unsigned int i = 0; i < args->num_enable_repos; i++) + cli_set_repo_enabled(p, args->enable_repos[i], 1); // Disable repositories - for (unsigned int i = 0; i < config->num_disable_repos; i++) - cli_set_repo_enabled(p, config->disable_repos[i], 0); + for (unsigned int i = 0; i < args->num_disable_repos; i++) + cli_set_repo_enabled(p, args->disable_repos[i], 0); // Return pointer *pakfire = p; ERROR: - if (c) - pakfire_config_unref(c); + if (config) + pakfire_config_unref(config); if (f) fclose(f); diff --git a/src/cli/lib/pakfire.h b/src/cli/lib/pakfire.h index 669ff86ee..553b146bd 100644 --- a/src/cli/lib/pakfire.h +++ b/src/cli/lib/pakfire.h @@ -26,7 +26,7 @@ #define MAX_REPOS 16 -struct cli_config { +struct cli_global_args { struct pakfire_ctx* ctx; const char* distro; @@ -43,6 +43,6 @@ struct cli_config { unsigned int num_disable_repos; }; -int cli_setup_pakfire(struct pakfire** pakfire, struct cli_config* config); +int cli_setup_pakfire(struct pakfire** pakfire, struct cli_global_args* args); #endif /* PAKFIRE_CLI_PAKFIRE_H */ diff --git a/src/cli/lib/provides.c b/src/cli/lib/provides.c index 3fb2751d3..475ba4f5a 100644 --- a/src/cli/lib/provides.c +++ b/src/cli/lib/provides.c @@ -33,20 +33,20 @@ static const char* doc = "Search for packages that provide a certain pattern"; #define MAX_PATTERNS 256 -struct config { +struct cli_local_args { char* patterns[MAX_PATTERNS]; unsigned int num_patterns; }; static error_t parse(int key, char* arg, struct argp_state* state, void* data) { - struct config* config = data; + struct cli_local_args* args = data; switch (key) { case ARGP_KEY_ARG: - if (config->num_patterns >= MAX_PATTERNS) + if (args->num_patterns >= MAX_PATTERNS) return -ENOBUFS; - config->patterns[config->num_patterns++] = arg; + args->patterns[args->num_patterns++] = arg; break; default: @@ -57,32 +57,30 @@ static error_t parse(int key, char* arg, struct argp_state* state, void* data) { } int cli_provides(void* data, int argc, char* argv[]) { + struct cli_global_args* global_args = data; + struct cli_local_args local_args = {}; 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, 0, argc, argv, &config); + r = cli_parse(NULL, NULL, args_doc, doc, parse, 0, argc, argv, &local_args); if (r) goto ERROR; // Setup pakfire - r = cli_setup_pakfire(&pakfire, cli_config); + r = cli_setup_pakfire(&pakfire, global_args); if (r) goto ERROR; // Allocate a new packagelist - r = pakfire_packagelist_create(&list, cli_config->ctx); + r = pakfire_packagelist_create(&list, global_args->ctx); if (r) goto ERROR; // Perform search - for (unsigned int i = 0; i < config.num_patterns; i++) { - r = pakfire_whatprovides(pakfire, config.patterns[i], 0, list); + for (unsigned int i = 0; i < local_args.num_patterns; i++) { + r = pakfire_whatprovides(pakfire, local_args.patterns[i], 0, list); if (r) goto ERROR; } diff --git a/src/cli/lib/remove.c b/src/cli/lib/remove.c index 7c654aa13..a175cf534 100644 --- a/src/cli/lib/remove.c +++ b/src/cli/lib/remove.c @@ -33,7 +33,7 @@ static const char* doc = "Remove packages"; #define MAX_PACKAGES 128 -struct config { +struct cli_local_args { int job_flags; // Packages @@ -51,18 +51,18 @@ static struct argp_option options[] = { }; static error_t parse(int key, char* arg, struct argp_state* state, void* data) { - struct config* config = data; + struct cli_local_args* args = data; switch (key) { case OPT_KEEP_DEPENDENCIES: - config->job_flags |= PAKFIRE_JOB_KEEP_DEPS; + args->job_flags |= PAKFIRE_JOB_KEEP_DEPS; break; case ARGP_KEY_ARG: - if (config->num_packages >= MAX_PACKAGES) + if (args->num_packages >= MAX_PACKAGES) return -ENOBUFS; - config->packages[config->num_packages++] = arg; + args->packages[args->num_packages++] = arg; break; default: @@ -73,12 +73,12 @@ static error_t parse(int key, char* arg, struct argp_state* state, void* data) { } static int __cli_remove(struct pakfire_transaction* transaction, int argc, char* argv[], void* data) { - struct config* config = (struct config*)data; + struct cli_local_args* args = data; int r; - for (unsigned int i = 0; i < config->num_packages; i++) { + for (unsigned int i = 0; i < args->num_packages; i++) { r = pakfire_transaction_request(transaction, - PAKFIRE_JOB_ERASE, config->packages[i], config->job_flags); + PAKFIRE_JOB_ERASE, args->packages[i], args->job_flags); if (r) { fprintf(stderr, "Could not find '%s': %m\n", argv[i]); return r; @@ -89,23 +89,22 @@ static int __cli_remove(struct pakfire_transaction* transaction, int argc, char* } int cli_remove(void* data, int argc, char* argv[]) { + struct cli_global_args* global_args = data; + struct cli_local_args local_args = {}; struct pakfire* pakfire = NULL; - struct config config = {}; int r; - struct cli_config* cli_config = data; - // Parse the command line - r = cli_parse(options, NULL, args_doc, doc, parse, 0, argc, argv, &config); + r = cli_parse(options, NULL, args_doc, doc, parse, 0, argc, argv, &local_args); if (r) goto ERROR; // Setup Pakfire - r = cli_setup_pakfire(&pakfire, cli_config); + r = cli_setup_pakfire(&pakfire, global_args); if (r) goto ERROR; - r = cli_transaction(pakfire, argc, argv, 0, __cli_remove, &config); + r = cli_transaction(pakfire, argc, argv, 0, __cli_remove, &local_args); ERROR: if (pakfire) diff --git a/src/cli/lib/repo_compose.c b/src/cli/lib/repo_compose.c index 120b5ab9c..3a87b41dd 100644 --- a/src/cli/lib/repo_compose.c +++ b/src/cli/lib/repo_compose.c @@ -33,7 +33,7 @@ static const char* doc = "Create a new repository"; #define MAX_PACKAGES 1024 -struct config { +struct cli_local_args { const char* path; const char* key; @@ -51,22 +51,22 @@ static struct argp_option options[] = { }; static error_t parse(int key, char* arg, struct argp_state* state, void* data) { - struct config* config = data; + struct cli_local_args* args = data; switch (key) { case OPT_KEY: - config->key = arg; + args->key = arg; break; case ARGP_KEY_ARG: - if (!config->path) - config->path = arg; + if (!args->path) + args->path = arg; - else if (config->num_packages >= MAX_PACKAGES) + else if (args->num_packages >= MAX_PACKAGES) return -ENOBUFS; else - config->packages[config->num_packages++] = arg; + args->packages[args->num_packages++] = arg; break; default: @@ -102,36 +102,31 @@ static int cli_import_key(struct pakfire_key** key, } int cli_repo_compose(void* data, int argc, char* argv[]) { + struct cli_global_args* global_args = data; + struct cli_local_args local_args = {}; struct pakfire* pakfire = NULL; struct pakfire_key* key = NULL; int r; - struct cli_config* cli_config = data; - - struct config config = { - .path = NULL, - .key = NULL, - }; - // Parse the command line - r = cli_parse(options, NULL, args_doc, doc, parse, 0, argc, argv, &config); + r = cli_parse(options, NULL, args_doc, doc, parse, 0, argc, argv, &local_args); if (r) goto ERROR; // Setup pakfire - r = cli_setup_pakfire(&pakfire, cli_config); + r = cli_setup_pakfire(&pakfire, global_args); if (r) goto ERROR; // Read the key (if any) - if (config.key) { - r = cli_import_key(&key, cli_config->ctx, config.key); + if (local_args.key) { + r = cli_import_key(&key, global_args->ctx, local_args.key); if (r) goto ERROR; } // Write the repository - r = pakfire_repo_compose(pakfire, config.path, key, (const char**)config.packages); + r = pakfire_repo_compose(pakfire, local_args.path, key, (const char**)local_args.packages); ERROR: if (key) diff --git a/src/cli/lib/repo_create.c b/src/cli/lib/repo_create.c index f825f47bb..ba270f579 100644 --- a/src/cli/lib/repo_create.c +++ b/src/cli/lib/repo_create.c @@ -33,7 +33,7 @@ static const char* args_doc = "DISTRO NAME [OPTIONS...]"; static const char* doc = "Create a new repository"; -struct config { +struct cli_local_args { const char* distro; const char* name; const char* description; @@ -48,19 +48,19 @@ static struct argp_option options[] = { }; static error_t parse(int key, char* arg, struct argp_state* state, void* data) { - struct config* config = data; + struct cli_local_args* args = data; switch (key) { case OPT_DESCRIPTION: - config->description = arg; + args->description = arg; break; case ARGP_KEY_ARG: - if (!config->distro) - config->distro = arg; + if (!args->distro) + args->distro = arg; - else if (!config->name) - config->name = arg; + else if (!args->name) + args->name = arg; else argp_usage(state); @@ -74,26 +74,25 @@ static error_t parse(int key, char* arg, struct argp_state* state, void* data) { } int cli_repo_create(void* data, int argc, char* argv[]) { + struct cli_global_args* global_args = data; + struct cli_local_args local_args = {}; struct pakfire_buildservice* service = NULL; struct json_object* repo = NULL; - struct config config = {}; int r; - struct cli_config* cli_config = data; - // Parse the command line - r = cli_parse(options, NULL, args_doc, doc, parse, 0, argc, argv, &config); + r = cli_parse(options, NULL, args_doc, doc, parse, 0, argc, argv, &local_args); if (r) goto ERROR; // Connect to the build service - r = pakfire_buildservice_create(&service, cli_config->ctx); + r = pakfire_buildservice_create(&service, global_args->ctx); if (r) goto ERROR; // List repos r = pakfire_buildservice_create_repo(service, - config.distro, config.name, config.description, &repo); + local_args.distro, local_args.name, local_args.description, &repo); if (r) goto ERROR; diff --git a/src/cli/lib/repo_delete.c b/src/cli/lib/repo_delete.c index 84a0ace4c..3ad30425e 100644 --- a/src/cli/lib/repo_delete.c +++ b/src/cli/lib/repo_delete.c @@ -33,21 +33,21 @@ static const char* args_doc = "DISTRO NAME"; static const char* doc = "Delete a repository"; -struct config { +struct cli_local_args { const char* distro; const char* name; }; static error_t parse(int key, char* arg, struct argp_state* state, void* data) { - struct config* config = data; + struct cli_local_args* args = data; switch (key) { case ARGP_KEY_ARG: - if (!config->distro) - config->distro = arg; + if (!args->distro) + args->distro = arg; - else if (!config->name) - config->name = arg; + else if (!args->name) + args->name = arg; else argp_usage(state); @@ -61,25 +61,24 @@ static error_t parse(int key, char* arg, struct argp_state* state, void* data) { } int cli_repo_delete(void* data, int argc, char* argv[]) { + struct cli_global_args* global_args = data; + struct cli_local_args local_args = {}; struct pakfire_buildservice* service = NULL; struct json_object* repo = NULL; - struct config config = {}; int r; - struct cli_config* cli_config = data; - // Parse the command line - r = cli_parse(NULL, NULL, args_doc, doc, parse, 0, argc, argv, &config); + r = cli_parse(NULL, NULL, args_doc, doc, parse, 0, argc, argv, &local_args); if (r) goto ERROR; // Connect to the build service - r = pakfire_buildservice_create(&service, cli_config->ctx); + r = pakfire_buildservice_create(&service, global_args->ctx); if (r) goto ERROR; // Delete the repository - r = pakfire_buildservice_delete_repo(service, config.distro, config.name); + r = pakfire_buildservice_delete_repo(service, local_args.distro, local_args.name); if (r) goto ERROR; diff --git a/src/cli/lib/repo_list.c b/src/cli/lib/repo_list.c index a00c2bb79..f3b40e635 100644 --- a/src/cli/lib/repo_list.c +++ b/src/cli/lib/repo_list.c @@ -29,17 +29,17 @@ static const char* doc = "Lists all repositories"; -struct config { +struct cli_local_args { const char* distro; }; static error_t parse(int key, char* arg, struct argp_state* state, void* data) { - struct config* config = data; + struct cli_local_args* args = data; switch (key) { case ARGP_KEY_ARG: - if (!config->distro) - config->distro = arg; + if (!args->distro) + args->distro = arg; else argp_usage(state); @@ -53,25 +53,24 @@ static error_t parse(int key, char* arg, struct argp_state* state, void* data) { } int cli_repo_list(void* data, int argc, char* argv[]) { + struct cli_global_args* global_args = data; + struct cli_local_args local_args = {}; struct pakfire_buildservice* service = NULL; struct json_object* repos = NULL; - struct config config = {}; int r; - struct cli_config* cli_config = data; - // Parse the command line - r = cli_parse(NULL, NULL, NULL, doc, parse, 0, argc, argv, &config); + r = cli_parse(NULL, NULL, NULL, doc, parse, 0, argc, argv, &local_args); if (r) goto ERROR; // Connect to the build service - r = pakfire_buildservice_create(&service, cli_config->ctx); + r = pakfire_buildservice_create(&service, global_args->ctx); if (r) goto ERROR; // List repos - r = pakfire_buildservice_list_repos(service, config.distro, &repos); + r = pakfire_buildservice_list_repos(service, local_args.distro, &repos); if (r) goto ERROR; diff --git a/src/cli/lib/repo_show.c b/src/cli/lib/repo_show.c index 9bdc7c794..e7794db38 100644 --- a/src/cli/lib/repo_show.c +++ b/src/cli/lib/repo_show.c @@ -31,21 +31,21 @@ static const char* doc = "Lists all repositories"; -struct config { +struct cli_local_args { const char* distro; const char* name; }; static error_t parse(int key, char* arg, struct argp_state* state, void* data) { - struct config* config = data; + struct cli_local_args* args = data; switch (key) { case ARGP_KEY_ARG: - if (!config->distro) - config->distro = arg; + if (!args->distro) + args->distro = arg; - else if (!config->name) - config->name = arg; + else if (!args->name) + args->name = arg; else argp_usage(state); @@ -59,25 +59,24 @@ static error_t parse(int key, char* arg, struct argp_state* state, void* data) { } int cli_repo_show(void* data, int argc, char* argv[]) { + struct cli_global_args* global_args = data; + struct cli_local_args local_args = {}; struct pakfire_buildservice* service = NULL; struct json_object* repo = NULL; - struct config config = {}; int r; - struct cli_config* cli_config = data; - // Parse the command line - r = cli_parse(NULL, NULL, NULL, doc, parse, 0, argc, argv, &config); + r = cli_parse(NULL, NULL, NULL, doc, parse, 0, argc, argv, &local_args); if (r) goto ERROR; // Connect to the build service - r = pakfire_buildservice_create(&service, cli_config->ctx); + r = pakfire_buildservice_create(&service, global_args->ctx); if (r) goto ERROR; // List repos - r = pakfire_buildservice_get_repo(service, config.distro, config.name, &repo); + r = pakfire_buildservice_get_repo(service, local_args.distro, local_args.name, &repo); if (r) goto ERROR; diff --git a/src/cli/lib/repolist.c b/src/cli/lib/repolist.c index b2d9a689f..dc7b414b3 100644 --- a/src/cli/lib/repolist.c +++ b/src/cli/lib/repolist.c @@ -31,19 +31,18 @@ static const char* doc = "List all available repositories"; int cli_repolist(void* data, int argc, char* argv[]) { + struct cli_global_args* global_args = data; struct pakfire* pakfire = NULL; struct pakfire_repolist* list = NULL; int r; - struct cli_config* cli_config = data; - // Parse the command line r = cli_parse(NULL, NULL, NULL, doc, NULL, 0, argc, argv, NULL); if (r) goto ERROR; // Setup Pakfire - r = cli_setup_pakfire(&pakfire, cli_config); + r = cli_setup_pakfire(&pakfire, global_args); if (r) goto ERROR; diff --git a/src/cli/lib/requires.c b/src/cli/lib/requires.c index f9d349feb..fce0195a6 100644 --- a/src/cli/lib/requires.c +++ b/src/cli/lib/requires.c @@ -33,20 +33,20 @@ static const char* doc = "Search for packages that requires a certain pattern"; #define MAX_PATTERNS 256 -struct config { +struct cli_local_args { char* patterns[MAX_PATTERNS]; unsigned int num_patterns; }; static error_t parse(int key, char* arg, struct argp_state* state, void* data) { - struct config* config = data; + struct cli_local_args* args = data; switch (key) { case ARGP_KEY_ARG: - if (config->num_patterns >= MAX_PATTERNS) + if (args->num_patterns >= MAX_PATTERNS) return -ENOBUFS; - config->patterns[config->num_patterns++] = arg; + args->patterns[args->num_patterns++] = arg; break; default: @@ -57,32 +57,30 @@ static error_t parse(int key, char* arg, struct argp_state* state, void* data) { } int cli_requires(void* data, int argc, char* argv[]) { + struct cli_global_args* global_args = data; + struct cli_local_args local_args = {}; 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, 0, argc, argv, &config); + r = cli_parse(NULL, NULL, args_doc, doc, parse, 0, argc, argv, &local_args); if (r) goto ERROR; // Setup pakfire - r = cli_setup_pakfire(&pakfire, cli_config); + r = cli_setup_pakfire(&pakfire, global_args); if (r) goto ERROR; // Allocate a new packagelist - r = pakfire_packagelist_create(&list, cli_config->ctx); + r = pakfire_packagelist_create(&list, global_args->ctx); if (r) goto ERROR; // Perform search - for (unsigned int i = 0; i < config.num_patterns; i++) { - r = pakfire_whatrequires(pakfire, config.patterns[i], 0, list); + for (unsigned int i = 0; i < local_args.num_patterns; i++) { + r = pakfire_whatrequires(pakfire, local_args.patterns[i], 0, list); if (r) goto ERROR; } diff --git a/src/cli/lib/search.c b/src/cli/lib/search.c index 9aa7c986b..0fa76a29e 100644 --- a/src/cli/lib/search.c +++ b/src/cli/lib/search.c @@ -33,20 +33,20 @@ static const char* doc = "Search for packages"; #define MAX_PATTERNS 256 -struct config { +struct cli_local_args { char* patterns[MAX_PATTERNS]; unsigned int num_patterns; }; static error_t parse(int key, char* arg, struct argp_state* state, void* data) { - struct config* config = data; + struct cli_local_args* args = data; switch (key) { case ARGP_KEY_ARG: - if (config->num_patterns >= MAX_PATTERNS) + if (args->num_patterns >= MAX_PATTERNS) return -ENOBUFS; - config->patterns[config->num_patterns++] = arg; + args->patterns[args->num_patterns++] = arg; break; default: @@ -57,32 +57,30 @@ static error_t parse(int key, char* arg, struct argp_state* state, void* data) { } int cli_search(void* data, int argc, char* argv[]) { + struct cli_global_args* global_args = data; + struct cli_local_args local_args = {}; 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, 0, argc, argv, &config); + r = cli_parse(NULL, NULL, args_doc, doc, parse, 0, argc, argv, &local_args); if (r) goto ERROR; // Setup pakfire - r = cli_setup_pakfire(&pakfire, cli_config); + r = cli_setup_pakfire(&pakfire, global_args); if (r) goto ERROR; // Allocate a new packagelist - r = pakfire_packagelist_create(&list, cli_config->ctx); + r = pakfire_packagelist_create(&list, global_args->ctx); if (r) goto ERROR; // Perform search - for (unsigned int i = 0; i < config.num_patterns; i++) { - r = pakfire_search(pakfire, config.patterns[i], 0, list); + for (unsigned int i = 0; i < local_args.num_patterns; i++) { + r = pakfire_search(pakfire, local_args.patterns[i], 0, list); if (r) goto ERROR; } diff --git a/src/cli/lib/shell.c b/src/cli/lib/shell.c index 4f2d3c512..d3271bb3e 100644 --- a/src/cli/lib/shell.c +++ b/src/cli/lib/shell.c @@ -31,7 +31,7 @@ #define MAX_ARGS 128 #define MAX_PACKAGES 128 -struct config { +struct cli_local_args { const char* distro; enum { @@ -64,29 +64,29 @@ static struct argp_option options[] = { }; static error_t parse(int key, char* arg, struct argp_state* state, void* data) { - struct config* config = data; + struct cli_local_args* args = data; switch (key) { case OPT_DISTRO: - config->distro = arg; + args->distro = arg; break; case OPT_DISABLE_SNAPSHOT: - config->flags &= ~SHELL_ENABLE_SNAPSHOT; + args->flags &= ~SHELL_ENABLE_SNAPSHOT; break; case OPT_INSTALL: - if (config->num_packages >= MAX_PACKAGES) + if (args->num_packages >= MAX_PACKAGES) return -ENOBUFS; - config->packages[config->num_packages++] = arg; + args->packages[args->num_packages++] = arg; break; case ARGP_KEY_ARG: - if (config->argc >= MAX_ARGS) + if (args->argc >= MAX_ARGS) return -ENOBUFS; - config->argv[config->argc++] = arg; + args->argv[args->argc++] = arg; break; default: @@ -97,56 +97,55 @@ static error_t parse(int key, char* arg, struct argp_state* state, void* data) { } int cli_shell(void* data, int argc, char* argv[]) { - struct cli_config* cli_config = data; - struct pakfire_config* c = NULL; - struct pakfire_build* build = NULL; - int build_flags = PAKFIRE_BUILD_INTERACTIVE; - int r; - - struct config config = { + struct cli_global_args* global_args = data; + struct cli_local_args local_args = { .flags = SHELL_ENABLE_SNAPSHOT, .argv = {}, .argc = 0, .packages = {}, .num_packages = 0, }; + struct pakfire_config* config = NULL; + struct pakfire_build* build = NULL; + int build_flags = PAKFIRE_BUILD_INTERACTIVE; + int r; // Parse the command line - r = cli_parse(options, NULL, NULL, doc, parse, 0, argc, argv, &config); + r = cli_parse(options, NULL, NULL, doc, parse, 0, argc, argv, &local_args); if (r) goto ERROR; // Enable snapshots? - if (config.flags & SHELL_ENABLE_SNAPSHOT) + if (local_args.flags & SHELL_ENABLE_SNAPSHOT) build_flags |= PAKFIRE_BUILD_ENABLE_SNAPSHOT; // Read distro configuration - r = cli_read_distro_config(&c, cli_config->ctx, config.distro); + r = cli_read_distro_config(&config, global_args->ctx, local_args.distro); if (r < 0) goto ERROR; // Setup the build environment - r = pakfire_build_create(&build, cli_config->ctx, c, cli_config->arch, NULL, build_flags); + r = pakfire_build_create(&build, global_args->ctx, config, global_args->arch, NULL, build_flags); if (r) { fprintf(stderr, "Could not setup the build environment: %m\n"); goto ERROR; } // Install any additional packages - if (config.num_packages) { - r = pakfire_build_install(build, config.packages); + if (local_args.num_packages) { + r = pakfire_build_install(build, local_args.packages); if (r) goto ERROR; } // Run the command - r = pakfire_build_shell(build, (config.argc) ? config.argv : NULL); + r = pakfire_build_shell(build, (local_args.argc) ? local_args.argv : NULL); ERROR: if (build) pakfire_build_unref(build); - if (c) - pakfire_config_unref(c); + if (config) + pakfire_config_unref(config); return r; } diff --git a/src/cli/lib/snapshot_update.c b/src/cli/lib/snapshot_update.c index 2f5fa2e72..78ad89ac8 100644 --- a/src/cli/lib/snapshot_update.c +++ b/src/cli/lib/snapshot_update.c @@ -29,18 +29,17 @@ static const char* doc = "Update the snapshot"; int cli_snapshot_update(void* data, int argc, char* argv[]) { + struct cli_global_args* global_args = data; struct pakfire* pakfire = NULL; int r; - struct cli_config* cli_config = data; - // Parse the command line r = cli_parse(NULL, NULL, NULL, doc, NULL, 0, argc, argv, NULL); if (r) goto ERROR; // Setup pakfire - r = cli_setup_pakfire(&pakfire, cli_config); + r = cli_setup_pakfire(&pakfire, global_args); if (r) goto ERROR; diff --git a/src/cli/lib/sync.c b/src/cli/lib/sync.c index b5ea449df..b0dd77e86 100644 --- a/src/cli/lib/sync.c +++ b/src/cli/lib/sync.c @@ -31,7 +31,7 @@ static const char* args_doc = "sync [OPTIONS...]"; static const char* doc = "Synchronize packages"; -struct config { +struct cli_local_args { int job_flags; }; @@ -45,11 +45,11 @@ static struct argp_option options[] = { }; static error_t parse(int key, char* arg, struct argp_state* state, void* data) { - struct config* config = data; + struct cli_local_args* args = data; switch (key) { case OPT_KEEP_ORPHANED: - config->job_flags |= PAKFIRE_JOB_KEEP_ORPHANED; + args->job_flags |= PAKFIRE_JOB_KEEP_ORPHANED; break; default: @@ -60,11 +60,11 @@ static error_t parse(int key, char* arg, struct argp_state* state, void* data) { } static int __cli_sync(struct pakfire_transaction* transaction, int argc, char* argv[], void* data) { - struct config* config = (struct config*)data; + struct cli_local_args* args = data; int r; // Request sync - r = pakfire_transaction_request(transaction, PAKFIRE_JOB_SYNC, NULL, config->job_flags); + r = pakfire_transaction_request(transaction, PAKFIRE_JOB_SYNC, NULL, args->job_flags); if (r) { fprintf(stderr, "Could not request job: %m\n"); return r; @@ -74,23 +74,22 @@ static int __cli_sync(struct pakfire_transaction* transaction, int argc, char* a } int cli_sync(void* data, int argc, char* argv[]) { + struct cli_global_args* global_args = data; + struct cli_local_args local_args = {}; struct pakfire* pakfire = NULL; - struct config config = {}; int r; - struct cli_config* cli_config = data; - // Parse the command line - r = cli_parse(options, NULL, args_doc, doc, parse, 0, argc, argv, &config); + r = cli_parse(options, NULL, args_doc, doc, parse, 0, argc, argv, &local_args); if (r) goto ERROR; // Setup Pakfire - r = cli_setup_pakfire(&pakfire, cli_config); + r = cli_setup_pakfire(&pakfire, global_args); if (r) goto ERROR; - r = cli_transaction(pakfire, argc, argv, 0, __cli_sync, &config); + r = cli_transaction(pakfire, argc, argv, 0, __cli_sync, &local_args); ERROR: if (pakfire) diff --git a/src/cli/lib/update.c b/src/cli/lib/update.c index b80ef2431..074c3f97a 100644 --- a/src/cli/lib/update.c +++ b/src/cli/lib/update.c @@ -34,7 +34,7 @@ static const char* doc = "Update packages"; #define MAX_EXCLUDES 128 #define MAX_PACKAGES 128 -struct config { +struct cli_local_args { int transaction_flags; // Excludes @@ -59,29 +59,29 @@ static struct argp_option options[] = { }; static error_t parse(int key, char* arg, struct argp_state* state, void* data) { - struct config* config = data; + struct cli_local_args* args = data; switch (key) { case OPT_ALLOW_DOWNGRADE: - config->transaction_flags |= PAKFIRE_TRANSACTION_ALLOW_DOWNGRADE; + args->transaction_flags |= PAKFIRE_TRANSACTION_ALLOW_DOWNGRADE; break; case OPT_ALLOW_UNINSTALL: - config->transaction_flags |= PAKFIRE_TRANSACTION_ALLOW_UNINSTALL; + args->transaction_flags |= PAKFIRE_TRANSACTION_ALLOW_UNINSTALL; break; case 'x': - if (config->num_excludes >= MAX_EXCLUDES) + if (args->num_excludes >= MAX_EXCLUDES) return -ENOBUFS; - config->excludes[config->num_excludes++] = arg; + args->excludes[args->num_excludes++] = arg; break; case ARGP_KEY_ARG: - if (config->num_packages >= MAX_PACKAGES) + if (args->num_packages >= MAX_PACKAGES) return -ENOBUFS; - config->packages[config->num_packages++] = arg; + args->packages[args->num_packages++] = arg; break; default: @@ -92,12 +92,12 @@ static error_t parse(int key, char* arg, struct argp_state* state, void* data) { } static int __cli_update(struct pakfire_transaction* transaction, int argc, char* argv[], void* data) { - struct config* config = (struct config*)data; + struct cli_local_args* args = data; int r; // Exclude any packages - for (unsigned int i = 0; i < config->num_excludes; i++) { - r = pakfire_transaction_request(transaction, PAKFIRE_JOB_LOCK, config->excludes[i], 0); + for (unsigned int i = 0; i < args->num_excludes; i++) { + r = pakfire_transaction_request(transaction, PAKFIRE_JOB_LOCK, args->excludes[i], 0); if (r) return r; } @@ -105,9 +105,9 @@ static int __cli_update(struct pakfire_transaction* transaction, int argc, char* // Did the user pass any packages? if (argc) { // Add the remaining command line options as packages - for (unsigned int i = 0; i < config->num_packages; i++) { + for (unsigned int i = 0; i < args->num_packages; i++) { r = pakfire_transaction_request(transaction, - PAKFIRE_JOB_UPDATE, config->packages[i], 0); + PAKFIRE_JOB_UPDATE, args->packages[i], 0); if (r) { fprintf(stderr, "Could not find '%s': %m\n", argv[i]); return r; @@ -125,23 +125,22 @@ static int __cli_update(struct pakfire_transaction* transaction, int argc, char* } int cli_update(void* data, int argc, char* argv[]) { + struct cli_global_args* global_args = data; + struct cli_local_args local_args = {}; struct pakfire* pakfire = NULL; - struct config config = {}; int r; - struct cli_config* cli_config = data; - // Parse the command line - r = cli_parse(options, NULL, args_doc, doc, parse, 0, argc, argv, &config); + r = cli_parse(options, NULL, args_doc, doc, parse, 0, argc, argv, &local_args); if (r) goto ERROR; // Setup Pakfire - r = cli_setup_pakfire(&pakfire, cli_config); + r = cli_setup_pakfire(&pakfire, global_args); if (r) goto ERROR; - r = cli_transaction(pakfire, argc, argv, config.transaction_flags, __cli_update, &config); + r = cli_transaction(pakfire, argc, argv, local_args.transaction_flags, __cli_update, &local_args); ERROR: if (pakfire) diff --git a/src/cli/lib/upload_create.c b/src/cli/lib/upload_create.c index e0d3b4498..04a7cef54 100644 --- a/src/cli/lib/upload_create.c +++ b/src/cli/lib/upload_create.c @@ -32,20 +32,20 @@ static const char* doc = "Uploads a file"; #define MAX_FILES 32 -struct config { +struct cli_local_args { const char* files[MAX_FILES]; unsigned int num_files; }; static error_t parse(int key, char* arg, struct argp_state* state, void* data) { - struct config* config = data; + struct cli_local_args* args = data; switch (key) { case ARGP_KEY_ARG: - if (config->num_files >= MAX_FILES) + if (args->num_files >= MAX_FILES) return -ENOBUFS; - config->files[config->num_files++] = arg; + args->files[args->num_files++] = arg; break; default: @@ -56,31 +56,30 @@ static error_t parse(int key, char* arg, struct argp_state* state, void* data) { } int cli_upload_create(void* data, int argc, char* argv[]) { + struct cli_global_args* global_args = data; + struct cli_local_args local_args = {}; struct pakfire_buildservice* service = NULL; - struct config config = {}; char* uuid = NULL; int r; - struct cli_config* cli_config = data; - // Parse the command line - r = cli_parse(NULL, NULL, args_doc, doc, parse, 0, argc, argv, &config); + r = cli_parse(NULL, NULL, args_doc, doc, parse, 0, argc, argv, &local_args); if (r) goto ERROR; // Connect to the build service - r = pakfire_buildservice_create(&service, cli_config->ctx); + r = pakfire_buildservice_create(&service, global_args->ctx); if (r) goto ERROR; // List uploads - for (unsigned int i = 0; i < config.num_files; i++) { - r = pakfire_buildservice_upload(service, config.files[i], NULL, &uuid); + for (unsigned int i = 0; i < local_args.num_files; i++) { + r = pakfire_buildservice_upload(service, local_args.files[i], NULL, &uuid); if (r) goto ERROR; if (uuid) { - printf("Uploaded %s as %s\n", config.files[i], uuid); + printf("Uploaded %s as %s\n", local_args.files[i], uuid); free(uuid); } } diff --git a/src/cli/lib/upload_delete.c b/src/cli/lib/upload_delete.c index eeb09191f..b019ff2ce 100644 --- a/src/cli/lib/upload_delete.c +++ b/src/cli/lib/upload_delete.c @@ -33,24 +33,24 @@ static const char* doc = "Deletes an uploaded file"; #define MAX_UPLOADS 32 -struct config { +struct cli_local_args { const char* uploads[MAX_UPLOADS]; unsigned int num_uploads; }; static error_t parse(int key, char* arg, struct argp_state* state, void* data) { - struct config* config = data; + struct cli_local_args* args = data; switch (key) { case ARGP_KEY_ARG: - if (config->num_uploads >= MAX_UPLOADS) + if (args->num_uploads >= MAX_UPLOADS) return -ENOBUFS; // Validate the UUID if (!pakfire_uuid_is_valid(arg)) argp_error(state, "Invalid UUID"); - config->uploads[config->num_uploads++] = arg; + args->uploads[args->num_uploads++] = arg; break; default: @@ -61,25 +61,24 @@ static error_t parse(int key, char* arg, struct argp_state* state, void* data) { } int cli_upload_delete(void* data, int argc, char* argv[]) { + struct cli_global_args* global_args = data; + struct cli_local_args local_args = {}; struct pakfire_buildservice* service = NULL; - struct config config = {}; int r; - struct cli_config* cli_config = data; - // Parse the command line - r = cli_parse(NULL, NULL, args_doc, doc, parse, 0, argc, argv, &config); + r = cli_parse(NULL, NULL, args_doc, doc, parse, 0, argc, argv, &local_args); if (r) goto ERROR; // Connect to the build service - r = pakfire_buildservice_create(&service, cli_config->ctx); + r = pakfire_buildservice_create(&service, global_args->ctx); if (r) goto ERROR; // Delete uploads - for (unsigned int i = 0; i < config.num_uploads; i++) { - r = pakfire_buildservice_delete_upload(service, config.uploads[i]); + for (unsigned int i = 0; i < local_args.num_uploads; i++) { + r = pakfire_buildservice_delete_upload(service, local_args.uploads[i]); if (r) goto ERROR; } diff --git a/src/cli/lib/upload_list.c b/src/cli/lib/upload_list.c index c8e5697e4..4ca7a7ced 100644 --- a/src/cli/lib/upload_list.c +++ b/src/cli/lib/upload_list.c @@ -30,19 +30,18 @@ static const char* doc = "Lists all uploads"; int cli_upload_list(void* data, int argc, char* argv[]) { + struct cli_global_args* global_args = data; struct pakfire_buildservice* service = NULL; struct json_object* uploads = NULL; int r; - struct cli_config* cli_config = data; - // Parse the command line r = cli_parse(NULL, NULL, NULL, doc, NULL, 0, argc, argv, NULL); if (r) goto ERROR; // Connect to the build service - r = pakfire_buildservice_create(&service, cli_config->ctx); + r = pakfire_buildservice_create(&service, global_args->ctx); if (r) goto ERROR; diff --git a/src/cli/pakfire-builder.c b/src/cli/pakfire-builder.c index 6731d14cf..d0aa30303 100644 --- a/src/cli/pakfire-builder.c +++ b/src/cli/pakfire-builder.c @@ -102,7 +102,7 @@ const char* args_doc = "snapshot [COMMAND...]"; static error_t parse(int key, char* arg, struct argp_state* state, void* data) { - struct cli_config* config = data; + struct cli_global_args* args = data; switch (key) { case OPT_ARCH: @@ -110,31 +110,31 @@ static error_t parse(int key, char* arg, struct argp_state* state, void* data) { if (!pakfire_arch_is_supported_by_host(arg)) argp_failure(state, EXIT_FAILURE, 0, "Unsupported architecture: %s", arg); - config->arch = arg; + args->arch = arg; break; case OPT_DEBUG: - pakfire_ctx_set_log_level(config->ctx, LOG_DEBUG); + pakfire_ctx_set_log_level(args->ctx, LOG_DEBUG); break; case OPT_DISTRO: - config->distro = arg; + args->distro = arg; break; // Enable/Disable Repositories case OPT_ENABLE_REPO: - if (config->num_enable_repos >= MAX_REPOS) + if (args->num_enable_repos >= MAX_REPOS) return -ENOBUFS; - config->enable_repos[config->num_enable_repos++] = arg; + args->enable_repos[args->num_enable_repos++] = arg; break; case OPT_DISABLE_REPO: - if (config->num_disable_repos >= MAX_REPOS) + if (args->num_disable_repos >= MAX_REPOS) return -ENOBUFS; - config->disable_repos[config->num_disable_repos++] = arg; + args->disable_repos[args->num_disable_repos++] = arg; break; default: @@ -173,7 +173,7 @@ int main(int argc, char* argv[]) { if (r) goto ERROR; - struct cli_config config = { + struct cli_global_args args = { .ctx = ctx, .distro = cli_get_default_distro(ctx), .arch = NULL, @@ -182,7 +182,7 @@ int main(int argc, char* argv[]) { // Parse the command line and run any commands r = cli_parse(options, commands, args_doc, NULL, - parse, CLI_REQUIRE_ROOT, argc, argv, &config); + parse, CLI_REQUIRE_ROOT, argc, argv, &args); ERROR: if (ctx) diff --git a/src/cli/pakfire-client.c b/src/cli/pakfire-client.c index b0d957e8d..3b99a0676 100644 --- a/src/cli/pakfire-client.c +++ b/src/cli/pakfire-client.c @@ -58,15 +58,15 @@ static struct argp_option options[] = { }; static error_t parse(int key, char* arg, struct argp_state* state, void* data) { - struct cli_config* config = data; + struct cli_global_args* args = data; switch (key) { case OPT_DEBUG: - pakfire_ctx_set_log_level(config->ctx, LOG_DEBUG); + pakfire_ctx_set_log_level(args->ctx, LOG_DEBUG); break; case OPT_DISTRO: - config->distro = arg; + args->distro = arg; break; default: @@ -88,14 +88,14 @@ int main(int argc, char* argv[]) { // Setup progress callback pakfire_ctx_set_progress_callback(ctx, cli_setup_progressbar, NULL); - struct cli_config config = { + struct cli_global_args args = { .ctx = ctx, .distro = cli_get_default_distro(ctx), }; // Parse the command line and run any commands r = cli_parse(options, commands, args_doc, doc, - parse, 0, argc, argv, &config); + parse, 0, argc, argv, &args); ERROR: if (ctx) diff --git a/src/cli/pakfire.c b/src/cli/pakfire.c index 78e97f8a2..d83737ea5 100644 --- a/src/cli/pakfire.c +++ b/src/cli/pakfire.c @@ -89,43 +89,43 @@ static const struct command commands[] = { }; static error_t parse(int key, char* arg, struct argp_state* state, void* data) { - struct cli_config* config = data; + struct cli_global_args* args = data; switch (key) { case OPT_CONFIG: - config->config = arg; + args->config = arg; break; case OPT_DEBUG: - pakfire_ctx_set_log_level(config->ctx, LOG_DEBUG); + pakfire_ctx_set_log_level(args->ctx, LOG_DEBUG); break; case OPT_OFFLINE: - pakfire_ctx_set_flag(config->ctx, PAKFIRE_CTX_OFFLINE); + pakfire_ctx_set_flag(args->ctx, PAKFIRE_CTX_OFFLINE); break; case OPT_ROOT: - config->root = arg; + args->root = arg; break; case OPT_YES: - pakfire_ctx_set_confirm_callback(config->ctx, cli_term_confirm_yes, NULL); + pakfire_ctx_set_confirm_callback(args->ctx, cli_term_confirm_yes, NULL); break; // Enable/Disable Repositories case OPT_ENABLE_REPO: - if (config->num_enable_repos >= MAX_REPOS) + if (args->num_enable_repos >= MAX_REPOS) return -ENOBUFS; - config->enable_repos[config->num_enable_repos++] = arg; + args->enable_repos[args->num_enable_repos++] = arg; break; case OPT_DISABLE_REPO: - if (config->num_disable_repos >= MAX_REPOS) + if (args->num_disable_repos >= MAX_REPOS) return -ENOBUFS; - config->disable_repos[config->num_disable_repos++] = arg; + args->disable_repos[args->num_disable_repos++] = arg; break; default: @@ -154,7 +154,7 @@ int main(int argc, char* argv[]) { // Setup pick solution callback pakfire_ctx_set_pick_solution_callback(ctx, cli_term_pick_solution, NULL); - struct cli_config config = { + struct cli_global_args args = { .ctx = ctx, // XXX hard-coded path .config = "/etc/pakfire/general.conf", @@ -166,7 +166,7 @@ int main(int argc, char* argv[]) { // Parse the command line and run any commands r = cli_parse(options, commands, args_doc, NULL, parse, - CLI_REQUIRE_ROOT, argc, argv, &config); + CLI_REQUIRE_ROOT, argc, argv, &args); ERROR: if (ctx) -- 2.47.2