[systemd-commits] 4 commits - man/hostnamectl.xml man/machine-info.xml shell-completion/bash shell-completion/zsh src/hostname src/shared src/test

Zbigniew Jędrzejewski-Szmek zbyszek at kemper.freedesktop.org
Fri Jul 11 06:22:55 PDT 2014


 man/hostnamectl.xml               |   94 ++++++++++++++++++++++++--------------
 man/machine-info.xml              |   17 ++++++
 shell-completion/bash/hostnamectl |    5 +-
 shell-completion/zsh/_hostnamectl |   41 +++++++++++++++-
 shell-completion/zsh/_localectl   |    4 -
 src/hostname/hostnamectl.c        |   20 ++++++--
 src/hostname/hostnamed.c          |   46 ++++++++++++++++--
 src/shared/util.c                 |    2 
 src/test/test-util.c              |   15 ++++++
 9 files changed, 197 insertions(+), 47 deletions(-)

New commits:
commit 1cb1767a29458b3d16d6b161b4ee34dd496ff60d
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Fri Jul 11 09:21:15 2014 -0400

    util: fix has cc check and add test

diff --git a/src/shared/util.c b/src/shared/util.c
index 3342798..75dc58b 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -5419,7 +5419,7 @@ bool string_has_cc(const char *p, const char *ok) {
 
         for (t = p; *t; t++) {
                 if (ok && strchr(ok, *t))
-                        return false;
+                        continue;
 
                 if (*t > 0 && *t < ' ')
                         return true;
diff --git a/src/test/test-util.c b/src/test/test-util.c
index 44921bd..ed91a67 100644
--- a/src/test/test-util.c
+++ b/src/test/test-util.c
@@ -731,6 +731,20 @@ static void test_filename_is_safe(void) {
         assert_se(filename_is_safe("o.o"));
 }
 
+static void test_string_has_cc(void) {
+        assert_se(string_has_cc("abc\1", NULL));
+        assert_se(string_has_cc("abc\x7f", NULL));
+        assert_se(string_has_cc("abc\x7f", NULL));
+        assert_se(string_has_cc("abc\t\x7f", "\t"));
+        assert_se(string_has_cc("abc\t\x7f", "\t"));
+        assert_se(string_has_cc("\x7f", "\t"));
+        assert_se(string_has_cc("\x7f", "\t\a"));
+
+        assert_se(!string_has_cc("abc\t\t", "\t"));
+        assert_se(!string_has_cc("abc\t\t\a", "\t\a"));
+        assert_se(!string_has_cc("a\ab\tc", "\t\a"));
+}
+
 static void test_ascii_strlower(void) {
         char a[] = "AabBcC Jk Ii Od LKJJJ kkd LK";
         assert_se(streq(ascii_strlower(a), "aabbcc jk ii od lkjjj kkd lk"));
@@ -937,6 +951,7 @@ int main(int argc, char *argv[]) {
         test_log2i();
         test_foreach_string();
         test_filename_is_safe();
+        test_string_has_cc();
         test_ascii_strlower();
         test_files_same();
         test_is_valid_documentation_url();

commit ccb03ac39d5360433e62b8b82e474aa044421bd9
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Fri Jul 11 09:08:47 2014 -0400

    shell-completion: add hostnamectl set-deployment

diff --git a/shell-completion/bash/hostnamectl b/shell-completion/bash/hostnamectl
index 22f8f06..a5e3460 100644
--- a/shell-completion/bash/hostnamectl
+++ b/shell-completion/bash/hostnamectl
@@ -38,7 +38,7 @@ _hostnamectl() {
         local -A VERBS=(
                 [STANDALONE]='status'
                      [ICONS]='set-icon-name'
-                      [NAME]='set-hostname'
+                      [NAME]='set-hostname set-deployment'
                    [CHASSIS]='set-chassis'
         )
 
diff --git a/shell-completion/zsh/_hostnamectl b/shell-completion/zsh/_hostnamectl
index be86876..e02f6de 100644
--- a/shell-completion/zsh/_hostnamectl
+++ b/shell-completion/zsh/_hostnamectl
@@ -25,6 +25,14 @@ _hostnamectl_set-chassis() {
     fi
 }
 
+_hostnamectl_set-deployment() {
+    if (( CURRENT <= 3 )); then
+        _message "new environment"
+    else
+        _message "no more options"
+    fi
+}
+
 _hostnamectl_command() {
     local -a _hostnamectl_cmds
     _hostnamectl_cmds=(
@@ -32,6 +40,7 @@ _hostnamectl_command() {
         "set-hostname:Set system hostname"
         "set-icon-name:Set icon name for host"
         "set-chassis:Set chassis type for host"
+        "set-deployment:Set deployment environment"
     )
     if (( CURRENT == 1 )); then
         _describe -t commands 'hostnamectl commands' _hostnamectl_cmds || compadd "$@"

commit 799298d6513e7d40125c19d46578bb870d047db4
Author: Jóhann B. Guðmundsson <johannbg at gmail.com>
Date:   Tue Jul 8 21:26:05 2014 +0000

    Add DEPLOYMENT to hostnamectl
    
    [zj: remove the check against a fixed list of environments.]

diff --git a/man/hostnamectl.xml b/man/hostnamectl.xml
index a158e67..99f984f 100644
--- a/man/hostnamectl.xml
+++ b/man/hostnamectl.xml
@@ -231,6 +231,27 @@
                                 </listitem>
                         </varlistentry>
 
+                        <varlistentry>
+                                <term><command>set-deployment <replaceable>ENVIRONMENT</replaceable></command></term>
+
+                                <listitem><para>Set the deployment
+                                environment description.
+                                <replaceable>ENVIRONMENT</replaceable>
+                                must be a single word without any
+                                control characters. One of the
+                                following is suggested:
+                                <literal>development</literal>,
+                                <literal>integration</literal>,
+                                <literal>staging</literal>,
+                                <literal>production</literal>.
+                                </para>
+
+                                <para>Pass an empty string to reset to
+                                the default empty value.</para>
+                                </listitem>
+                        </varlistentry>
+
+
                 </variablelist>
         </refsect1>
 
diff --git a/man/machine-info.xml b/man/machine-info.xml
index 244e9b6..a2ad4e6 100644
--- a/man/machine-info.xml
+++ b/man/machine-info.xml
@@ -157,6 +157,20 @@
                                 available.</para></listitem>
                         </varlistentry>
 
+                        <varlistentry>
+                                <term><varname>DEPLOYMENT=</varname></term>
+
+                                <listitem><para>Describes the system
+                                deployment environment. One of the
+                                following is suggested:
+                                <literal>development</literal>,
+                                <literal>integration</literal>,
+                                <literal>staging</literal>,
+                                <literal>production</literal>.
+                                </para></listitem>
+                        </varlistentry>
+
+
                 </variablelist>
 
         </refsect1>
@@ -166,7 +180,8 @@
 
                 <programlisting>PRETTY_HOSTNAME="Lennart's Tablet"
 ICON_NAME=computer-tablet
-CHASSIS=tablet</programlisting>
+CHASSIS=tablet
+DEPLOYMENT=production</programlisting>
         </refsect1>
 
         <refsect1>
diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c
index 267cd74..7e6922b 100644
--- a/src/hostname/hostnamectl.c
+++ b/src/hostname/hostnamectl.c
@@ -67,6 +67,7 @@ typedef struct StatusInfo {
         char *pretty_hostname;
         char *icon_name;
         char *chassis;
+        char *deployment;
         char *kernel_name;
         char *kernel_release;
         char *os_pretty_name;
@@ -92,9 +93,11 @@ static void print_status_info(StatusInfo *i) {
                 printf("Transient hostname: %s\n", i->hostname);
 
         printf("         Icon name: %s\n"
-               "           Chassis: %s\n",
+               "           Chassis: %s\n"
+               "        Deployment: %s\n",
                strna(i->icon_name),
-               strna(i->chassis));
+               strna(i->chassis),
+               strna(i->deployment));
 
         r = sd_id128_get_machine(&mid);
         if (r >= 0)
@@ -157,6 +160,7 @@ static int show_all_names(sd_bus *bus) {
                 { "PrettyHostname", "s", NULL, offsetof(StatusInfo, pretty_hostname) },
                 { "IconName",       "s", NULL, offsetof(StatusInfo, icon_name) },
                 { "Chassis",        "s", NULL, offsetof(StatusInfo, chassis) },
+                { "Deployment",        "s", NULL, offsetof(StatusInfo, deployment) },
                 { "KernelName",     "s", NULL, offsetof(StatusInfo, kernel_name) },
                 { "KernelRelease",     "s", NULL, offsetof(StatusInfo, kernel_release) },
                 { "OperatingSystemPrettyName",     "s", NULL, offsetof(StatusInfo, os_pretty_name) },
@@ -194,6 +198,7 @@ fail:
         free(info.pretty_hostname);
         free(info.icon_name);
         free(info.chassis);
+        free(info.deployment);
         free(info.kernel_name);
         free(info.kernel_release);
         free(info.os_pretty_name);
@@ -309,6 +314,13 @@ static int set_chassis(sd_bus *bus, char **args, unsigned n) {
         return set_simple_string(bus, "SetChassis", args[1]);
 }
 
+static int set_deployment(sd_bus *bus, char **args, unsigned n) {
+        assert(args);
+        assert(n == 2);
+
+        return set_simple_string(bus, "SetDeployment", args[1]);
+}
+
 static int help(void) {
 
         printf("%s [OPTIONS...] COMMAND ...\n\n"
@@ -325,7 +337,8 @@ static int help(void) {
                "  status                 Show current hostname settings\n"
                "  set-hostname NAME      Set system hostname\n"
                "  set-icon-name NAME     Set icon name for host\n"
-               "  set-chassis NAME       Set chassis type for host\n",
+               "  set-chassis NAME       Set chassis type for host\n"
+               "  set-deployment NAME    Set deployment environment for host\n",
                program_invocation_short_name);
 
         return 0;
@@ -423,6 +436,7 @@ static int hostnamectl_main(sd_bus *bus, int argc, char *argv[]) {
                 { "set-hostname",  EQUAL, 2, set_hostname  },
                 { "set-icon-name", EQUAL, 2, set_icon_name },
                 { "set-chassis",   EQUAL, 2, set_chassis   },
+                { "set-deployment",   EQUAL, 2, set_deployment   },
         };
 
         int left;
diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c
index eaae113..a4849b3 100644
--- a/src/hostname/hostnamed.c
+++ b/src/hostname/hostnamed.c
@@ -35,12 +35,15 @@
 #include "bus-util.h"
 #include "event-util.h"
 
+#define VALID_DEPLOYMENT_CHARS (DIGITS LETTERS "-.:")
+
 enum {
         PROP_HOSTNAME,
         PROP_STATIC_HOSTNAME,
         PROP_PRETTY_HOSTNAME,
         PROP_ICON_NAME,
         PROP_CHASSIS,
+        PROP_DEPLOYMENT,
         PROP_KERNEL_NAME,
         PROP_KERNEL_RELEASE,
         PROP_KERNEL_VERSION,
@@ -100,6 +103,7 @@ static int context_read_data(Context *c) {
                            "PRETTY_HOSTNAME", &c->data[PROP_PRETTY_HOSTNAME],
                            "ICON_NAME", &c->data[PROP_ICON_NAME],
                            "CHASSIS", &c->data[PROP_CHASSIS],
+                           "DEPLOYMENT", &c->data[PROP_DEPLOYMENT],
                            NULL);
         if (r < 0 && r != -ENOENT)
                 return r;
@@ -134,7 +138,6 @@ static bool check_nss(void) {
 }
 
 static bool valid_chassis(const char *chassis) {
-
         assert(chassis);
 
         return nulstr_contains(
@@ -149,6 +152,12 @@ static bool valid_chassis(const char *chassis) {
                         chassis);
 }
 
+static bool valid_deployment(const char *deployment) {
+        assert(deployment);
+
+        return strspn(deployment, VALID_DEPLOYMENT_CHARS) == strlen(deployment);
+}
+
 static const char* fallback_chassis(void) {
         int r;
         char *type;
@@ -258,6 +267,7 @@ static char* context_fallback_icon_name(Context *c) {
         return strdup("computer");
 }
 
+
 static bool hostname_is_useful(const char *hn) {
         return !isempty(hn) && !is_localhost(hn);
 }
@@ -312,7 +322,8 @@ static int context_write_data_machine_info(Context *c) {
         static const char * const name[_PROP_MAX] = {
                 [PROP_PRETTY_HOSTNAME] = "PRETTY_HOSTNAME",
                 [PROP_ICON_NAME] = "ICON_NAME",
-                [PROP_CHASSIS] = "CHASSIS"
+                [PROP_CHASSIS] = "CHASSIS",
+                [PROP_DEPLOYMENT] = "DEPLOYMENT",
         };
 
         _cleanup_strv_free_ char **l = NULL;
@@ -324,7 +335,7 @@ static int context_write_data_machine_info(Context *c) {
         if (r < 0 && r != -ENOENT)
                 return r;
 
-        for (p = PROP_PRETTY_HOSTNAME; p <= PROP_CHASSIS; p++) {
+        for (p = PROP_PRETTY_HOSTNAME; p <= PROP_DEPLOYMENT; p++) {
                 char *t, **u;
 
                 assert(name[p]);
@@ -402,6 +413,23 @@ static int property_get_chassis(
         return sd_bus_message_append(reply, "s", name);
 }
 
+static int property_get_deployment(
+                sd_bus *bus,
+                const char *path,
+                const char *interface,
+                const char *property,
+                sd_bus_message *reply,
+                void *userdata,
+                sd_bus_error *error) {
+
+        Context *c = userdata;
+        const char *name;
+
+        name = c->data[PROP_DEPLOYMENT];
+
+        return sd_bus_message_append(reply, "s", name);
+}
+
 static int method_set_hostname(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *error) {
         Context *c = userdata;
         const char *name;
@@ -555,6 +583,8 @@ static int set_machine_info(Context *c, sd_bus *bus, sd_bus_message *m, int prop
                         return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid pretty host name '%s'", name);
                 if (prop == PROP_CHASSIS && !valid_chassis(name))
                         return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid chassis '%s'", name);
+                if (prop == PROP_DEPLOYMENT && !valid_deployment(name))
+                        return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid deployment '%s'", name);
 
                 h = strdup(name);
                 if (!h)
@@ -572,11 +602,13 @@ static int set_machine_info(Context *c, sd_bus *bus, sd_bus_message *m, int prop
 
         log_info("Changed %s to '%s'",
                  prop == PROP_PRETTY_HOSTNAME ? "pretty host name" :
+                 prop == PROP_DEPLOYMENT ? "deployment" :
                  prop == PROP_CHASSIS ? "chassis" : "icon name", strna(c->data[prop]));
 
         sd_bus_emit_properties_changed(bus, "/org/freedesktop/hostname1", "org.freedesktop.hostname1",
                                        prop == PROP_PRETTY_HOSTNAME ? "PrettyHostname" :
-                                       prop == PROP_CHASSIS ? "Chassis" : "IconName", NULL);
+                                       prop == PROP_DEPLOYMENT ? "Deployment" :
+                                       prop == PROP_CHASSIS ? "Chassis" : "IconName" , NULL);
 
         return sd_bus_reply_method_return(m, NULL);
 }
@@ -593,6 +625,10 @@ static int method_set_chassis(sd_bus *bus, sd_bus_message *m, void *userdata, sd
         return set_machine_info(userdata, bus, m, PROP_CHASSIS, method_set_chassis, error);
 }
 
+static int method_set_deployment(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *error) {
+        return set_machine_info(userdata, bus, m, PROP_DEPLOYMENT, method_set_deployment, error);
+}
+
 static const sd_bus_vtable hostname_vtable[] = {
         SD_BUS_VTABLE_START(0),
         SD_BUS_PROPERTY("Hostname", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_HOSTNAME, 0),
@@ -600,6 +636,7 @@ static const sd_bus_vtable hostname_vtable[] = {
         SD_BUS_PROPERTY("PrettyHostname", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_PRETTY_HOSTNAME, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
         SD_BUS_PROPERTY("IconName", "s", property_get_icon_name, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
         SD_BUS_PROPERTY("Chassis", "s", property_get_chassis, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
+        SD_BUS_PROPERTY("Deployment", "s", property_get_deployment, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
         SD_BUS_PROPERTY("KernelName", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_KERNEL_NAME, SD_BUS_VTABLE_PROPERTY_CONST),
         SD_BUS_PROPERTY("KernelRelease", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_KERNEL_RELEASE, SD_BUS_VTABLE_PROPERTY_CONST),
         SD_BUS_PROPERTY("KernelVersion", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_KERNEL_VERSION, SD_BUS_VTABLE_PROPERTY_CONST),
@@ -610,6 +647,7 @@ static const sd_bus_vtable hostname_vtable[] = {
         SD_BUS_METHOD("SetPrettyHostname", "sb", NULL, method_set_pretty_hostname, SD_BUS_VTABLE_UNPRIVILEGED),
         SD_BUS_METHOD("SetIconName", "sb", NULL, method_set_icon_name, SD_BUS_VTABLE_UNPRIVILEGED),
         SD_BUS_METHOD("SetChassis", "sb", NULL, method_set_chassis, SD_BUS_VTABLE_UNPRIVILEGED),
+        SD_BUS_METHOD("SetDeployment", "sb", NULL, method_set_deployment, SD_BUS_VTABLE_UNPRIVILEGED),
         SD_BUS_VTABLE_END,
 };
 

commit 1ed774956406941d4812a3fb4493d2915f130f12
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Fri Jul 11 08:25:20 2014 -0400

    shell-completion,man: beef up chassis completions and description
    
    Parameters to hostnamectl command are not optional and should not be marked
    as such in the man page.

diff --git a/man/hostnamectl.xml b/man/hostnamectl.xml
index eac3040..a158e67 100644
--- a/man/hostnamectl.xml
+++ b/man/hostnamectl.xml
@@ -146,13 +146,14 @@
                         </varlistentry>
 
                         <varlistentry>
-                                <term><command>set-hostname [NAME]</command></term>
+                                <term><command>set-hostname <replaceable>NAME</replaceable></command></term>
 
                                 <listitem><para>Set the system
-                                hostname. By default, this will alter
-                                the pretty, the static, and the
-                                transient hostname alike; however, if
-                                one or more of
+                                hostname to
+                                <replaceable>NAME</replaceable>. By
+                                default, this will alter the pretty,
+                                the static, and the transient hostname
+                                alike; however, if one or more of
                                 <option>--static</option>,
                                 <option>--transient</option>,
                                 <option>--pretty</option> are used,
@@ -173,55 +174,61 @@
                                 the hostname string is not done if
                                 only the transient and/or static host
                                 names are set, and the pretty host
-                                name is left untouched. Pass the empty
-                                string <literal></literal> as the
-                                hostname to reset the selected
-                                hostnames to their default (usually
+                                name is left untouched.</para>
+
+                                <para>Pass the empty string
+                                <literal></literal> as the hostname to
+                                reset the selected hostnames to their
+                                default (usually
                                 <literal>localhost</literal>).</para></listitem>
                         </varlistentry>
 
                         <varlistentry>
-                                <term><command>set-icon-name [NAME]</command></term>
+                                <term><command>set-icon-name <replaceable>NAME</replaceable></command></term>
 
                                 <listitem><para>Set the system icon
-                                name. The icon name is used by some
-                                graphical applications to visualize
-                                this host. The icon name should follow
-                                the <ulink
+                                name to
+                                <replaceable>NAME</replaceable>. The
+                                icon name is used by some graphical
+                                applications to visualize this host.
+                                The icon name should follow the <ulink
                                 url="http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html">Icon
-                                Naming Specification</ulink>. Pass an
-                                empty string to this operation to
-                                reset the icon name to the default
-                                value, which is determined from chassis
-                                type (see below) and possibly other
+                                Naming Specification</ulink>.</para>
+
+                                <para>Pass an empty string to reset
+                                the icon name to the default value,
+                                which is determined from chassis type
+                                (see below) and possibly other
                                 parameters.</para></listitem>
                         </varlistentry>
 
                         <varlistentry>
-                                <term><command>set-chassis [TYPE]</command></term>
+                                <term><command>set-chassis <replaceable>TYPE</replaceable></command></term>
 
-                                <listitem><para>Set the chassis
-                                type. The chassis type is used by some
+                                <listitem><para>Set the chassis type
+                                to <replaceable>TYPE</replaceable>.
+                                The chassis type is used by some
                                 graphical applications to visualize
-                                the host or alter user
-                                interaction. Currently, the following
-                                chassis types are defined:
+                                the host or alter user interaction.
+                                Currently, the following chassis types
+                                are defined:
                                 <literal>desktop</literal>,
                                 <literal>laptop</literal>,
                                 <literal>server</literal>,
                                 <literal>tablet</literal>,
-				<literal>handset</literal>,
-				<literal>watch</literal>, as well as
+                                <literal>handset</literal>,
+                                <literal>watch</literal>, as well as
                                 the special chassis types
                                 <literal>vm</literal> and
                                 <literal>container</literal> for
                                 virtualized systems that lack an
-                                immediate physical chassis. Pass an
-                                empty string to this operation to
-                                reset the chassis type to the default
-                                value which is determined from the
-                                firmware and possibly other
-                                parameters.</para></listitem>
+                                immediate physical chassis.</para>
+
+                                <para>Pass an empty string to reset
+                                the chassis type to the default value
+                                which is determined from the firmware
+                                and possibly other parameters.</para>
+                                </listitem>
                         </varlistentry>
 
                 </variablelist>
diff --git a/shell-completion/bash/hostnamectl b/shell-completion/bash/hostnamectl
index 9c75da9..22f8f06 100644
--- a/shell-completion/bash/hostnamectl
+++ b/shell-completion/bash/hostnamectl
@@ -39,6 +39,7 @@ _hostnamectl() {
                 [STANDALONE]='status'
                      [ICONS]='set-icon-name'
                       [NAME]='set-hostname'
+                   [CHASSIS]='set-chassis'
         )
 
         for ((i=0; i < COMP_CWORD; i++)); do
@@ -50,6 +51,8 @@ _hostnamectl() {
 
         if [[ -z $verb ]]; then
                 comps=${VERBS[*]}
+        elif __contains_word "$verb" ${VERBS[CHASSIS]}; then
+                comps='desktop laptop server tablet handset watch vm container'
         elif __contains_word "$verb" ${VERBS[STANDALONE]} ${VERBS[ICONS]} ${VERBS[NAME]}; then
                 comps=''
         fi
diff --git a/shell-completion/zsh/_hostnamectl b/shell-completion/zsh/_hostnamectl
index 7effa04..be86876 100644
--- a/shell-completion/zsh/_hostnamectl
+++ b/shell-completion/zsh/_hostnamectl
@@ -1,5 +1,30 @@
 #compdef hostnamectl
 
+_hostnamectl_set-hostname() {
+    if (( CURRENT <= 3 )); then
+        _message "new hostname"
+    else
+        _message "no more options"
+    fi
+}
+
+_hostnamectl_set-icon-name() {
+    if (( CURRENT <= 3 )); then
+        _message "new icon name"
+    else
+        _message "no more options"
+    fi
+}
+
+_hostnamectl_set-chassis() {
+    if (( CURRENT <= 3 )); then
+        _chassis=( desktop laptop server tablet handset watch vm container )
+        _describe chassis _chassis
+    else
+        _message "no more options"
+    fi
+}
+
 _hostnamectl_command() {
     local -a _hostnamectl_cmds
     _hostnamectl_cmds=(
@@ -14,8 +39,11 @@ _hostnamectl_command() {
         local curcontext="$curcontext"
         cmd="${${_hostnamectl_cmds[(r)$words[1]:*]%%:*}}"
         if (( $#cmd )); then
-            [[ $cmd == status ]] && msg="no options" || msg="options for $cmd"
-            _message "$msg"
+            if [[ $cmd == status ]]; then
+                _message "no options"
+            else
+                _hostnamectl_$cmd
+            fi
         else
             _message "unknown hostnamectl command: $words[1]"
         fi
diff --git a/shell-completion/zsh/_localectl b/shell-completion/zsh/_localectl
index 87432da..d8af4d1 100644
--- a/shell-completion/zsh/_localectl
+++ b/shell-completion/zsh/_localectl
@@ -22,8 +22,8 @@ _localectl_set-locale() {
 
 _localectl_set-keymap() {
     local -a _keymaps
-    _keymaps=( ${(f)"$(_call_program locales "$service" list-keymaps)"} )
     if (( CURRENT <= 3 )); then
+        _keymaps=( ${(f)"$(_call_program locales "$service" list-keymaps)"} )
         _describe keymaps _keymaps
     else
         _message "no more options"
@@ -77,7 +77,7 @@ _localectl_command() {
         if (( $+functions[_localectl_$cmd] )); then
             _localectl_$cmd
         else
-            _message "no more options"
+            _message "unknown localectl command: $words[1]"
         fi
     fi
 }



More information about the systemd-commits mailing list