]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
userdbctl: always show summary after printing table (unless legend is off)
authorLennart Poettering <lennart@poettering.net>
Mon, 8 Nov 2021 16:36:42 +0000 (17:36 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 8 Nov 2021 20:40:30 +0000 (21:40 +0100)
We do this in many (most?) other tools, do so here too. It's quite
useful info to count users/groups/…

src/userdb/userdbctl.c

index 5f3831d70c0e99326b814648fe68cc477dbffddd..f7ef1a3ef56a1a4ce18a6a16104739aa26407637 100644 (file)
@@ -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;
 }