X Tutup
Skip to content

Commit 790e3ed

Browse files
committed
userdbctl: always show summary after printing table (unless legend is off)
We do this in many (most?) other tools, do so here too. It's quite useful info to count users/groups/…
1 parent 4083d82 commit 790e3ed

File tree

1 file changed

+46
-15
lines changed

1 file changed

+46
-15
lines changed

src/userdb/userdbctl.c

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,18 @@ static int display_user(int argc, char *argv[], void *userdata) {
184184
}
185185

186186
if (table) {
187-
r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, arg_legend);
188-
if (r < 0)
189-
return table_log_print_error(r);
187+
if (table_get_rows(table) > 1) {
188+
r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, arg_legend);
189+
if (r < 0)
190+
return table_log_print_error(r);
191+
}
192+
193+
if (arg_legend) {
194+
if (table_get_rows(table) > 1)
195+
printf("\n%zu users listed.\n", table_get_rows(table) - 1);
196+
else
197+
printf("No users.\n");
198+
}
190199
}
191200

192201
return ret;
@@ -340,9 +349,18 @@ static int display_group(int argc, char *argv[], void *userdata) {
340349
}
341350

342351
if (table) {
343-
r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, arg_legend);
344-
if (r < 0)
345-
return table_log_print_error(r);
352+
if (table_get_rows(table) > 1) {
353+
r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, arg_legend);
354+
if (r < 0)
355+
return table_log_print_error(r);
356+
}
357+
358+
if (arg_legend) {
359+
if (table_get_rows(table) > 1)
360+
printf("\n%zu groups listed.\n", table_get_rows(table) - 1);
361+
else
362+
printf("No groups.\n");
363+
}
346364
}
347365

348366
return ret;
@@ -478,9 +496,18 @@ static int display_memberships(int argc, char *argv[], void *userdata) {
478496
}
479497

480498
if (table) {
481-
r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, arg_legend);
482-
if (r < 0)
483-
return table_log_print_error(r);
499+
if (table_get_rows(table) > 1) {
500+
r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, arg_legend);
501+
if (r < 0)
502+
return table_log_print_error(r);
503+
}
504+
505+
if (arg_legend) {
506+
if (table_get_rows(table) > 1)
507+
printf("\n%zu memberships listed.\n", table_get_rows(table) - 1);
508+
else
509+
printf("No memberships.\n");
510+
}
484511
}
485512

486513
return ret;
@@ -541,14 +568,18 @@ static int display_services(int argc, char *argv[], void *userdata) {
541568
return table_log_add_error(r);
542569
}
543570

544-
if (table_get_rows(t) <= 0) {
545-
log_info("No services.");
546-
return 0;
571+
if (table_get_rows(t) > 1) {
572+
r = table_print_with_pager(t, arg_json_format_flags, arg_pager_flags, arg_legend);
573+
if (r < 0)
574+
return table_log_print_error(r);
547575
}
548576

549-
r = table_print_with_pager(t, arg_json_format_flags, arg_pager_flags, arg_legend);
550-
if (r < 0)
551-
return table_log_print_error(r);
577+
if (arg_legend) {
578+
if (table_get_rows(t) > 1)
579+
printf("\n%zu services listed.\n", table_get_rows(t) - 1);
580+
else
581+
printf("No services.\n");
582+
}
552583

553584
return 0;
554585
}

0 commit comments

Comments
 (0)
X Tutup