summaryrefslogtreecommitdiff
path: root/src/userdb
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-11-08 17:36:42 +0100
committerLennart Poettering <lennart@poettering.net>2021-11-08 21:40:30 +0100
commit790e3ed3cca2c45fb9332eadb8e35ed14b463bc8 (patch)
tree71e908f8752aea29179428dd6a810d5bea6e1967 /src/userdb
parent4083d825e9e82e6e7500da41d668d3a76c16fb98 (diff)
downloadsystemd-790e3ed3cca2c45fb9332eadb8e35ed14b463bc8.tar.gz
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/…
Diffstat (limited to 'src/userdb')
-rw-r--r--src/userdb/userdbctl.c61
1 files changed, 46 insertions, 15 deletions
diff --git a/src/userdb/userdbctl.c b/src/userdb/userdbctl.c
index 5f3831d70c..f7ef1a3ef5 100644
--- a/src/userdb/userdbctl.c
+++ b/src/userdb/userdbctl.c
@@ -184,9 +184,18 @@ static int display_user(int argc, char *argv[], void *userdata) {
}
if (table) {
- r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, arg_legend);
- if (r < 0)
- return table_log_print_error(r);
+ if (table_get_rows(table) > 1) {
+ r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, arg_legend);
+ if (r < 0)
+ return table_log_print_error(r);
+ }
+
+ if (arg_legend) {
+ if (table_get_rows(table) > 1)
+ printf("\n%zu users listed.\n", table_get_rows(table) - 1);
+ else
+ printf("No users.\n");
+ }
}
return ret;
@@ -340,9 +349,18 @@ static int display_group(int argc, char *argv[], void *userdata) {
}
if (table) {
- r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, arg_legend);
- if (r < 0)
- return table_log_print_error(r);
+ if (table_get_rows(table) > 1) {
+ r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, arg_legend);
+ if (r < 0)
+ return table_log_print_error(r);
+ }
+
+ if (arg_legend) {
+ if (table_get_rows(table) > 1)
+ printf("\n%zu groups listed.\n", table_get_rows(table) - 1);
+ else
+ printf("No groups.\n");
+ }
}
return ret;
@@ -478,9 +496,18 @@ static int display_memberships(int argc, char *argv[], void *userdata) {
}
if (table) {
- r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, arg_legend);
- if (r < 0)
- return table_log_print_error(r);
+ if (table_get_rows(table) > 1) {
+ r = table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, arg_legend);
+ if (r < 0)
+ return table_log_print_error(r);
+ }
+
+ if (arg_legend) {
+ if (table_get_rows(table) > 1)
+ printf("\n%zu memberships listed.\n", table_get_rows(table) - 1);
+ else
+ printf("No memberships.\n");
+ }
}
return ret;
@@ -541,14 +568,18 @@ static int display_services(int argc, char *argv[], void *userdata) {
return table_log_add_error(r);
}
- if (table_get_rows(t) <= 0) {
- log_info("No services.");
- return 0;
+ if (table_get_rows(t) > 1) {
+ r = table_print_with_pager(t, arg_json_format_flags, arg_pager_flags, arg_legend);
+ if (r < 0)
+ return table_log_print_error(r);
}
- r = table_print_with_pager(t, arg_json_format_flags, arg_pager_flags, arg_legend);
- if (r < 0)
- return table_log_print_error(r);
+ if (arg_legend) {
+ if (table_get_rows(t) > 1)
+ printf("\n%zu services listed.\n", table_get_rows(t) - 1);
+ else
+ printf("No services.\n");
+ }
return 0;
}