From: Michael Tremer Date: Tue, 1 Jul 2025 16:14:13 +0000 (+0000) Subject: cli: repolist: Use the new thing to format the table X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2360a9f30a57c1a06cbe672fc647dd04333cd5fb;p=pakfire.git cli: repolist: Use the new thing to format the table Signed-off-by: Michael Tremer --- diff --git a/src/cli/lib/repolist.c b/src/cli/lib/repolist.c index 7516af91..5a627acc 100644 --- a/src/cli/lib/repolist.c +++ b/src/cli/lib/repolist.c @@ -23,25 +23,25 @@ #include #include "command.h" -#include "dump.h" #include "pakfire.h" #include "repolist.h" +#include "table.h" static const char* doc = "List all available repositories"; #define REPO_FORMAT " %-20s %8s %12s %12s \n" static int cli_dump_repo(pakfire_root* root, pakfire_repo* repo, void* data) { - return printf(" %-20s %8s %12d %12d \n", - pakfire_repo_get_name(repo), - pakfire_repo_get_enabled(repo) ? "Yes" : "No", - pakfire_repo_get_priority(repo), - pakfire_repo_count(repo)); + cli_table* table = data; + + return cli_table_add_row(table, pakfire_repo_get_name(repo), + pakfire_repo_get_enabled(repo), pakfire_repo_get_priority(repo), pakfire_repo_count(repo)); } int cli_repolist(void* data, int argc, char* argv[]) { struct cli_global_args* global_args = data; pakfire_root* root = NULL; + cli_table* table = NULL; int r; // Parse the command line @@ -54,17 +54,42 @@ int cli_repolist(void* data, int argc, char* argv[]) { if (r) goto ERROR; - // Print the header - r = printf(" %-20s %8s %12s %12s \n", "Repository", "Enabled", "Priority", "Packages"); + // Create a new table + r = cli_table_create(&table); + if (r < 0) + goto ERROR; + + // Add a column with the name + r = cli_table_add_col(table, "Repository", CLI_TABLE_STRING, CLI_TABLE_ALIGN_LEFT); + if (r < 0) + goto ERROR; + + // Add enabled status + r = cli_table_add_col(table, "Enabled", CLI_TABLE_YESNO, CLI_TABLE_ALIGN_RIGHT); + if (r < 0) + goto ERROR; + + r = cli_table_add_col(table, "Priority", CLI_TABLE_INTEGER, CLI_TABLE_ALIGN_RIGHT); + if (r < 0) + goto ERROR; + + r = cli_table_add_col(table, "Packages", CLI_TABLE_INTEGER, CLI_TABLE_ALIGN_RIGHT); if (r < 0) goto ERROR; // Show all repositories - r = pakfire_root_repo_walk(root, cli_dump_repo, NULL); + r = pakfire_root_repo_walk(root, cli_dump_repo, table); + if (r < 0) + goto ERROR; + + // Print the table + r = cli_table_print(table, stdout); ERROR: if (root) pakfire_root_unref(root); + if (table) + cli_table_free(table); return r; }