chiark / gitweb /
systemctl: add help for --type/-t
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 15 Nov 2012 10:54:57 +0000 (11:54 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 15 Nov 2012 10:54:57 +0000 (11:54 +0100)
The list of types and load states if lengthy, so a little reminder
can be sometimes useful.

man/systemctl.xml
src/shared/unit-name.c
src/shared/unit-name.h
src/systemctl/systemctl.c

index 31f3b1a90986c48a71d884a805faf66ad380359d..62446d7a5747b407858870dc31a6ccdc34c98db4 100644 (file)
                                 certain unit types. If not specified
                                 units of in all load states will be
                                 shown.</para>
+
+                                <para>As a special case, if the argument
+                                is <option>help</option>, a list of
+                                allowed values will be printed and the
+                                program will exit.</para>
                                 </listitem>
                         </varlistentry>
 
index 50031e608e066b299b216dd4c8878167cafde49f..88ca0b8f2ccbf90025ab40f3877cebc7c8740c93 100644 (file)
@@ -33,7 +33,7 @@
         "ABCDEFGHIJKLMNOPQRSTUVWXYZ"            \
         ":-_.\\"
 
-static const char* const unit_type_table[_UNIT_TYPE_MAX] = {
+const char* const unit_type_table[_UNIT_TYPE_MAX] = {
         [UNIT_SERVICE] = "service",
         [UNIT_SOCKET] = "socket",
         [UNIT_TARGET] = "target",
@@ -48,7 +48,7 @@ static const char* const unit_type_table[_UNIT_TYPE_MAX] = {
 
 DEFINE_STRING_TABLE_LOOKUP(unit_type, UnitType);
 
-static const char* const unit_load_state_table[_UNIT_LOAD_STATE_MAX] = {
+const char* const unit_load_state_table[_UNIT_LOAD_STATE_MAX] = {
         [UNIT_STUB] = "stub",
         [UNIT_LOADED] = "loaded",
         [UNIT_ERROR] = "error",
index 7be346590e645546d2ec5a3f827460e2126f3097..d7528a3ac7ee735f6f0f5e39edf8e376e4e87144 100644 (file)
@@ -44,7 +44,7 @@ enum UnitType {
 };
 
 enum UnitLoadState {
-        UNIT_STUB,
+        UNIT_STUB = 0,
         UNIT_LOADED,
         UNIT_ERROR,
         UNIT_MERGED,
@@ -53,9 +53,11 @@ enum UnitLoadState {
         _UNIT_LOAD_STATE_INVALID = -1
 };
 
+extern const char* const unit_type_table[];
 const char *unit_type_to_string(UnitType i);
 UnitType unit_type_from_string(const char *s);
 
+extern const char* const unit_load_state_table[];
 const char *unit_load_state_to_string(UnitLoadState i);
 UnitLoadState unit_load_state_from_string(const char *s);
 
index 39f4e6c5093f8c8479e26212f6a6c136265a2ec3..f6eed1cc7f60593240cf824ecf593451e9e1e7e7 100644 (file)
@@ -4058,6 +4058,22 @@ static int runlevel_help(void) {
         return 0;
 }
 
+static int help_types(void) {
+        int i;
+
+        puts("Available unit types:");
+        for(i = UNIT_SERVICE; i < _UNIT_TYPE_MAX; i++)
+                if (unit_type_table[i])
+                        puts(unit_type_table[i]);
+
+        puts("\nAvailable unit load states: ");
+        for(i = UNIT_STUB; i < _UNIT_LOAD_STATE_MAX; i++)
+                if (unit_type_table[i])
+                        puts(unit_load_state_table[i]);
+
+        return 0;
+}
+
 static int systemctl_parse_argv(int argc, char *argv[]) {
 
         enum {
@@ -4137,6 +4153,11 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
                         return 0;
 
                 case 't':
+                        if (streq(optarg, "help")) {
+                                help_types();
+                                return 0;
+                        }
+
                         if (unit_type_from_string(optarg) >= 0) {
                                 arg_type = optarg;
                                 break;
@@ -4147,6 +4168,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
                         }
                         log_error("Unkown unit type or load state '%s'.",
                                   optarg);
+                        log_info("Use -t help to see a list of allowed values.");
                         return -EINVAL;
                 case 'p': {
                         char **l;