format-table: introduce table_isempty and use it where appropriate

This commit is contained in:
Mike Yuan
2023-12-25 17:47:18 +08:00
parent c01a5c0527
commit 2413a0fab4
15 changed files with 60 additions and 44 deletions
+4 -4
View File
@@ -235,7 +235,7 @@ static int show_table(Table *table, const char *word) {
assert(table);
assert(word);
if (table_get_rows(table) > 1 || OUTPUT_MODE_IS_JSON(arg_output)) {
if (!table_isempty(table) || OUTPUT_MODE_IS_JSON(arg_output)) {
r = table_set_sort(table, (size_t) 0);
if (r < 0)
return table_log_sort_error(r);
@@ -251,10 +251,10 @@ static int show_table(Table *table, const char *word) {
}
if (arg_legend) {
if (table_get_rows(table) > 1)
printf("\n%zu %s listed.\n", table_get_rows(table) - 1, word);
else
if (table_isempty(table))
printf("No %s.\n", word);
else
printf("\n%zu %s listed.\n", table_get_rows(table) - 1, word);
}
return 0;