]> git.ipfire.org Git - pakfire.git/commitdiff
cli: pakfire: Implement --yes
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 27 Sep 2023 15:43:29 +0000 (15:43 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 27 Sep 2023 15:43:29 +0000 (15:43 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/cli/lib/terminal.c
src/cli/lib/terminal.h
src/cli/pakfire/main.c

index 72702004b324e23991f38892b5ee0894f5c3875a..ad005029d442e9242db6532458c2c26707ce9b39 100644 (file)
@@ -88,6 +88,11 @@ END:
        return r;
 }
 
+int cli_term_confirm_yes(struct pakfire* pakfire,
+               void* data, const char* message, const char* question) {
+       return 0;
+}
+
 static int cli_term_enter_number(const char* question, unsigned int* choice,
                unsigned int min, unsigned int max) {
        char* line = NULL;
@@ -173,7 +178,6 @@ static struct pakfire_solution* cli_term_find_solution(
                struct pakfire_problem** problems, const unsigned int choice) {
        struct pakfire_solution* selected_solution = NULL;
        struct pakfire_solution** solutions = NULL;
-       int r;
 
        // Count solutions
        unsigned int i = 1;
index 7ff0f7134939bfe35b6ed39d950e2ad9e40b773d..5243ea41967f2cf44c95c9f347b213ccdb79bf66 100644 (file)
@@ -26,6 +26,8 @@
 
 int cli_term_confirm(struct pakfire* pakfire,
        void* data, const char* message, const char* question);
+int cli_term_confirm_yes(struct pakfire* pakfire,
+       void* data, const char* message, const char* question);
 
 int cli_term_pick_solution(
        struct pakfire* pakfire, struct pakfire_transaction* transaction, void* data);
index 6d0048a3ef49342fc6bacea83411ee0cc803f3d0..fe574d59f6703cd098df56760fe05fbb36b2cefe 100644 (file)
@@ -200,6 +200,23 @@ static int parse_argv(struct config* config, int argc, char* argv[]) {
        return 0;
 }
 
+static int configure_callbacks(const struct config* config, struct pakfire* pakfire) {
+       // If the user wants to answer yes to everything we only configure that
+       if (config->yes) {
+               pakfire_set_confirm_callback(pakfire, cli_term_confirm_yes, NULL);
+
+               return 0;
+       }
+
+       // Configure confirm callback
+       pakfire_set_confirm_callback(pakfire, cli_term_confirm, NULL);
+
+       // Configure pick solution callback
+       pakfire_set_pick_solution_callback(pakfire, cli_term_pick_solution, NULL);
+
+       return 0;
+}
+
 static void cli_set_repo_enabled(struct pakfire* pakfire, const char* name, int enabled) {
        struct pakfire_repo* repo = NULL;
 
@@ -249,10 +266,9 @@ int main(int argc, char* argv[]) {
                goto ERROR;
 
        // Configure callbacks
-       pakfire_set_confirm_callback(pakfire, cli_term_confirm, NULL);
-
-       // Configure pick solution callback
-       pakfire_set_pick_solution_callback(pakfire, cli_term_pick_solution, NULL);
+       r = configure_callbacks(&config, pakfire);
+       if (r)
+               goto ERROR;
 
        // Enable repositories
        for (unsigned int i = 0; i < config.num_enable_repos; i++)