]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl: add --state=help
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 28 Sep 2015 17:29:03 +0000 (13:29 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 28 Sep 2015 19:09:34 +0000 (15:09 -0400)
This mirrors --type=help and simplifies completion scripts.

The array of states is dense, so the is no need to check if the string is null.

man/systemctl.xml
src/systemctl/systemctl.c

index c1359d1678eb816e6ae28b9a10fd2cfbd93d2d0d..e8cd47339c925651bf9dd1d8361fd9ae355a4b08 100644 (file)
         <term><option>--state=</option></term>
 
         <listitem>
-        <para>The argument should be a comma-separated list of unit
-        LOAD, SUB, or ACTIVE states. When listing units, show only
-        those in specified states. Use <option>--state=failed</option>
-        to show only failed units.</para>
+          <para>The argument should be a comma-separated list of unit
+          LOAD, SUB, or ACTIVE states. When listing units, show only
+          those in specified states. Use <option>--state=failed</option>
+          to show only failed units.</para>
+
+          <para>As a special case, if one of the arguments is
+          <option>help</option>, a list of allowed values will be
+          printed and the program will exit.</para>
         </listitem>
       </varlistentry>
 
index 34e4751b9412cb25c744b801d0af4f03c8add96f..600d985978b51b1ca223ea9a9e3a6c08ea59b9a2 100644 (file)
@@ -6314,15 +6314,25 @@ static void runlevel_help(void) {
 
 static void help_types(void) {
         int i;
-        const char *t;
 
         if (!arg_no_legend)
                 puts("Available unit types:");
-        for (i = 0; i < _UNIT_TYPE_MAX; i++) {
-                t = unit_type_to_string(i);
-                if (t)
-                        puts(t);
-        }
+        for (i = 0; i < _UNIT_TYPE_MAX; i++)
+                puts(unit_type_to_string(i));
+}
+
+static void help_states(void) {
+        int i;
+
+        if (!arg_no_legend)
+                puts("Available unit load states:");
+        for (i = 0; i < _UNIT_LOAD_STATE_MAX; i++)
+                puts(unit_load_state_to_string(i));
+
+        if (!arg_no_legend)
+                puts("\nAvailable unit active states:");
+        for (i = 0; i < _UNIT_ACTIVE_STATE_MAX; i++)
+                puts(unit_active_state_to_string(i));
 }
 
 static int systemctl_parse_argv(int argc, char *argv[]) {
@@ -6660,6 +6670,11 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
                                 if (!s)
                                         return log_oom();
 
+                                if (streq(s, "help")) {
+                                        help_states();
+                                        return 0;
+                                }
+
                                 if (strv_consume(&arg_states, s) < 0)
                                         return log_oom();
                         }