]> git.ipfire.org Git - pakfire.git/commitdiff
cli: repolist: Use the new thing to format the table
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 1 Jul 2025 16:14:13 +0000 (16:14 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 1 Jul 2025 16:14:13 +0000 (16:14 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/cli/lib/repolist.c

index 7516af916969277183e60b80584c4c6b409fb005..5a627acc29824d40b2f7763e7b307b9bd349a98c 100644 (file)
 #include <pakfire/root.h>
 
 #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;
 }