From 45c0c61df3c63cb1f20505c8d292385d5e300578 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 15 Nov 2012 11:54:57 +0100 Subject: [PATCH] systemctl: add help for --type/-t The list of types and load states if lengthy, so a little reminder can be sometimes useful. --- man/systemctl.xml | 5 +++++ src/shared/unit-name.c | 4 ++-- src/shared/unit-name.h | 4 +++- src/systemctl/systemctl.c | 22 ++++++++++++++++++++++ 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/man/systemctl.xml b/man/systemctl.xml index 31f3b1a90..62446d7a5 100644 --- a/man/systemctl.xml +++ b/man/systemctl.xml @@ -106,6 +106,11 @@ certain unit types. If not specified units of in all load states will be shown. + + As a special case, if the argument + is , a list of + allowed values will be printed and the + program will exit. diff --git a/src/shared/unit-name.c b/src/shared/unit-name.c index 50031e608..88ca0b8f2 100644 --- a/src/shared/unit-name.c +++ b/src/shared/unit-name.c @@ -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", diff --git a/src/shared/unit-name.h b/src/shared/unit-name.h index 7be346590..d7528a3ac 100644 --- a/src/shared/unit-name.h +++ b/src/shared/unit-name.h @@ -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); diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 39f4e6c50..f6eed1cc7 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -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; -- 2.30.2