#include "dump.h"
#include "pakfire.h"
#include "repo_list.h"
+#include "table.h"
static const char* doc = "Lists all repositories";
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;
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++) {
// 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;
}