From: Michael Tremer Date: Tue, 1 Jul 2025 16:06:26 +0000 (+0000) Subject: cli: repo list: Use the new thing to format tables X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5ed3b33e5c8cd443db1a74f87e8a1a0c462dca7b;p=pakfire.git cli: repo list: Use the new thing to format tables Signed-off-by: Michael Tremer --- diff --git a/src/cli/lib/repo_list.c b/src/cli/lib/repo_list.c index 7b0a4367..7b99593f 100644 --- a/src/cli/lib/repo_list.c +++ b/src/cli/lib/repo_list.c @@ -28,6 +28,7 @@ #include "dump.h" #include "pakfire.h" #include "repo_list.h" +#include "table.h" static const char* doc = "Lists all repositories"; @@ -58,6 +59,7 @@ static int response_callback(struct pakfire_xfer* xfer, const pakfire_xfer_response* response, void* data) { struct cli_local_args* local_args = data; json_object* repo = NULL; + cli_table* table = NULL; const char* name = NULL; int64_t priority = 0; int r; @@ -67,8 +69,19 @@ static int response_callback(struct pakfire_xfer* xfer, if (r < 0) return 0; - // Show a header - printf("%-12s %-12s\n", "Name", "Priority"); + // Create a new table + r = cli_table_create(&table); + if (r < 0) + goto ERROR; + + // Add the header + r = cli_table_add_col(table, "Name", CLI_TABLE_STRING, CLI_TABLE_ALIGN_LEFT); + if (r < 0) + goto ERROR; + + r = cli_table_add_col(table, "Priority", CLI_TABLE_INTEGER, CLI_TABLE_ALIGN_RIGHT); + if (r < 0) + goto ERROR; // Loop through all repos for (size_t i = 0; i < json_object_array_length(response->data); i++) { @@ -79,16 +92,26 @@ static int response_callback(struct pakfire_xfer* xfer, // Fetch the name r = pakfire_json_get_string(repo, "name", &name); if (r < 0) - break; + goto ERROR; // Fetch the priority r = pakfire_json_get_int64(repo, "priority", &priority); if (r < 0) - break; + goto ERROR; - printf("%-12s %-12ld\n", name, priority); + // Add a new row to the table + r = cli_table_add_row(table, name, priority); + if (r < 0) + goto ERROR; } + // Print the table + r = cli_table_print(table, stdout); + +ERROR: + if (table) + cli_table_free(table); + return r; }