monitor: Add netdev_del id argument completion.
authorHani Benhabiles <kroosec@gmail.com>
Wed, 7 May 2014 22:41:32 +0000 (23:41 +0100)
committerLuiz Capitulino <lcapitulino@redhat.com>
Thu, 15 May 2014 19:16:02 +0000 (15:16 -0400)
Signed-off-by: Hani Benhabiles <hani@linux.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
hmp-commands.hx
hmp.h
monitor.c

index a7f9b2fd892117e1af57ed1c04cc48794ddc6ca5..2e462c04aaa1c6310565b19393ea8de678ebe8b6 100644 (file)
@@ -1252,6 +1252,7 @@ ETEXI
         .params     = "id",
         .help       = "remove host network device",
         .mhandler.cmd = hmp_netdev_del,
+        .command_completion = netdev_del_completion,
     },
 
 STEXI
diff --git a/hmp.h b/hmp.h
index bcecd0da160aa3e7390e42338a7b2b3641fcea43..aba59e95f06d9e690b08a95ea9ada544fd336103 100644 (file)
--- a/hmp.h
+++ b/hmp.h
@@ -102,5 +102,6 @@ void chardev_remove_completion(ReadLineState *rs, int nb_args, const char *str);
 void chardev_add_completion(ReadLineState *rs, int nb_args, const char *str);
 void set_link_completion(ReadLineState *rs, int nb_args, const char *str);
 void netdev_add_completion(ReadLineState *rs, int nb_args, const char *str);
+void netdev_del_completion(ReadLineState *rs, int nb_args, const char *str);
 
 #endif
index a3dd3614fcef679e74488f27536650840bba795a..593679a17a2fc62cddf33922c30062ac797ca17b 100644 (file)
--- a/monitor.c
+++ b/monitor.c
@@ -4493,6 +4493,32 @@ void set_link_completion(ReadLineState *rs, int nb_args, const char *str)
     }
 }
 
+void netdev_del_completion(ReadLineState *rs, int nb_args, const char *str)
+{
+    int len, count, i;
+    NetClientState *ncs[255];
+
+    if (nb_args != 2) {
+        return;
+    }
+
+    len = strlen(str);
+    readline_set_completion_index(rs, len);
+    count = qemu_find_net_clients_except(NULL, ncs, NET_CLIENT_OPTIONS_KIND_NIC,
+                                         255);
+    for (i = 0; i < count; i++) {
+        QemuOpts *opts;
+        const char *name = ncs[i]->name;
+        if (strncmp(str, name, len)) {
+            continue;
+        }
+        opts = qemu_opts_find(qemu_find_opts_err("netdev", NULL), name);
+        if (opts) {
+            readline_add_completion(rs, name);
+        }
+    }
+}
+
 static void monitor_find_completion_by_table(Monitor *mon,
                                              const mon_cmd_t *cmd_table,
                                              char **args,