[libvirt] [PATCH 1/2]virsh: introduce member exclude_option in vshCmdOptDef and improve auto complete with it

Chen Hanxiao chenhanxiao at cn.fujitsu.com
Fri Oct 25 03:46:19 UTC 2013


From: Chen Hanxiao <chenhanxiao at cn.fujitsu.com>

If we need to exclude one parameter from another,
we could use member 'exclude_option' to specify one.

With this flag, we could archive what Eric comments on:
https://www.redhat.com/archives/libvir-list/2013-October/msg00965.html
1. COMMAND <TAB> or COMMAND --<TAB>
Auto complete will NOT show option that marked as VSH_OT_ALIAS
2. COMMAND --sh<TAB>
Auto complete will show --shareable
(this one was marked as VSH_OT_ALIAS)
3. COMMAND --mode XXX <TAB> or COMMAND --mode XXX --sh<TAB>
Auto complete will NOT show --shareable
(we set new member exclude_option for mode)
4. COMMAND --shareable --mo<TAB>
Auto complete will NOT show --mode
(we set new member exclude_option for mode)

Signed-off-by: Chen Hanxiao <chenhanxiao at cn.fujitsu.com>
---
 tools/virsh.c | 8 ++++++++
 tools/virsh.h | 1 +
 2 files changed, 9 insertions(+)

diff --git a/tools/virsh.c b/tools/virsh.c
index bad78c9..93f525e 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -2686,6 +2686,7 @@ vshReadlineOptionsGenerator(const char *text, int state)
     static int list_index, len;
     static const vshCmdDef *cmd = NULL;
     const char *name;
+    const char *exclude_option;
 
     if (!state) {
         /* determine command name */
@@ -2712,6 +2713,7 @@ vshReadlineOptionsGenerator(const char *text, int state)
 
     while ((name = cmd->opts[list_index].name)) {
         const vshCmdOptDef *opt = &cmd->opts[list_index];
+        exclude_option = opt->exclude_option;
         char *res;
 
         list_index++;
@@ -2720,6 +2722,12 @@ vshReadlineOptionsGenerator(const char *text, int state)
             /* ignore non --option */
             continue;
 
+        if (len == 2 && opt->type == VSH_OT_ALIAS)
+            continue;
+
+        if (exclude_option && (strstr(rl_line_buffer, exclude_option)))
+            continue;
+
         if (len > 2) {
             if (STRNEQLEN(name, text + 2, len - 2))
                 continue;
diff --git a/tools/virsh.h b/tools/virsh.h
index b843788..89b284f 100644
--- a/tools/virsh.h
+++ b/tools/virsh.h
@@ -173,6 +173,7 @@ struct _vshCmdOptDef {
                                  * the name of a later public option */
     vshCompleter completer;         /* option completer */
     unsigned int completer_flags;   /* option completer flags */
+    const char *exclude_option;    /* check the exclusion of option */
 };
 
 /*
-- 
1.8.2.1




More information about the libvir-list mailing list