nmcli: extend `nmcli device set` command to accept explicit ifname specifier
authorThomas Haller <thaller@redhat.com>
Fri, 18 Sep 2015 08:49:19 +0000 (10:49 +0200)
committerThomas Haller <thaller@redhat.com>
Fri, 18 Sep 2015 11:14:44 +0000 (13:14 +0200)
Without it, you cannot set the properties of a device named "help".
Now you can with:

  $ nmcli device set ifname help autoconnect no

clients/cli/devices.c
clients/cli/nmcli-completion
man/nmcli.1.in

index 66f4ad3..b8b4a23 100644 (file)
@@ -259,7 +259,7 @@ usage (void)
                      "COMMAND := { status | show | connect | disconnect | delete | wifi }\n\n"
                      "  status\n\n"
                      "  show [<ifname>]\n\n"
-                     "  set <ifname> [autoconnect yes|no] [managed yes|no]\n\n"
+                     "  set [ifname] <ifname> [autoconnect yes|no] [managed yes|no]\n\n"
                      "  connect <ifname>\n\n"
                      "  disconnect <ifname> ...\n\n"
                      "  delete <ifname> ...\n\n"
@@ -338,7 +338,8 @@ usage_device_set (void)
 {
        g_printerr (_("Usage: nmcli device set { ARGUMENTS | help }\n"
                      "\n"
-                     "ARGUMENTS := <ifname> { PROPERTY [ PROPERTY ... ] }\n"
+                     "ARGUMENTS := DEVICE { PROPERTY [ PROPERTY ... ] }\n"
+                     "DEVICE    := [ifname] <ifname> \n"
                      "PROPERTY  := { autoconnect { yes | no } |\n"
                      "             { managed { yes | no }\n"
                      "\n"
@@ -1925,6 +1926,11 @@ do_device_set (NmCli *nmc, int argc, char **argv)
                [DEV_SET_MANAGED]     = { -1 },
        };
 
+       if (argc >= 1 && g_strcmp0 (*argv, "ifname") == 0) {
+               argc--;
+               argv++;
+       }
+
        if (argc == 0) {
                g_string_printf (nmc->return_text, _("Error: No interface specified."));
                nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
index a37e1fc..909c00e 100644 (file)
@@ -596,6 +596,7 @@ _nmcli_compl_ARGS()
 
 # some commands expect a connection as parameter. This connection can either be given
 # as id|uuid|path|apath. Parse that connection parameter.
+# Actually, it can also ask for a device name, like `nmcli device set [ifname] <ifname>`
 _nmcli_compl_ARGS_CONNECTION()
 {
     if ! _nmcli_array_has_value OPTIONS "${words[0]}"; then
@@ -1274,9 +1275,11 @@ _nmcli()
                         ;;
                     se|set)
                         if [[ ${#words[@]} -eq 3 ]]; then
-                            _nmcli_compl_COMMAND_nl "${words[2]}" "$(_nmcli_dev_status DEVICE)"
+                            _nmcli_compl_COMMAND_nl "${words[2]}" "$(printf "ifname\n%s" "$(_nmcli_con_show NAME)")"
                         else
-                            _nmcli_array_delete_at words 0 2
+                            _nmcli_array_delete_at words 0 1
+                            OPTIONS=(ifname)
+                            _nmcli_compl_ARGS_CONNECTION && return 0
                             OPTIONS=(autoconnect managed)
                             _nmcli_compl_ARGS
                         fi
index 49da025..15781c4 100644 (file)
@@ -774,7 +774,7 @@ examined. To get information for a specific device, the interface name has
 to be provided.
 .TP
 .TP
-.B set <ifname> [autoconnect yes|no] [managed yes|no]
+.B set [ifname] <ifname> [autoconnect yes|no] [managed yes|no]
 .br
 Set device properties.
 .TP