#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
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;
}