systemctl: do not suggest passing --all if the user passed --state=
authorAlan Jenkins <alan.christopher.jenkins@gmail.com>
Tue, 4 Dec 2018 17:31:51 +0000 (17:31 +0000)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 15 Jul 2019 11:37:29 +0000 (13:37 +0200)
"systemctl --failed" suggested I pass "--all" to see units in the inactive
state as well.  I thought this was not very useful.  If you explicitly
asked for units in a specific state, then you already know you have
narrowed it down.  And if you ran "systemctl --state=inactive", it is even
more strange to see this message.

@keszybz suggests we probably don't want to suggest "list-unit-files"
either :-).  Let's only suggest that if the user passed "--state=inactive".

Finally, this means the output for "systemctl --failed" could be just
"0 loaded units listed".  In this case, we don't need any highlight on that
text, to distinguish it from the hint.  This matches "list-unit-files".
This also means we happen to avoid using red highlight, when there are zero
failed units, as if that itself was a failure.  @kesbyz pointed out that
old behaviour was a bit weird.

src/systemctl/systemctl.c

index 52e3416..0305f61 100644 (file)
@@ -557,14 +557,16 @@ static int output_units_list(const UnitInfo *unit_infos, unsigned c) {
                         off = ansi_normal();
                 }
 
-                if (arg_all)
+                if (arg_all || strv_contains(arg_states, "inactive"))
                         printf("%s%u loaded units listed.%s\n"
                                "To show all installed unit files use 'systemctl list-unit-files'.\n",
                                on, n_shown, off);
-                else
+                else if (!arg_states)
                         printf("%s%u loaded units listed.%s Pass --all to see loaded but inactive units, too.\n"
                                "To show all installed unit files use 'systemctl list-unit-files'.\n",
                                on, n_shown, off);
+                else
+                        printf("%u loaded units listed.\n", n_shown);
         }
 
         return 0;