On 10/25/13 04:46, Chen Hanxiao wrote:
From: Chen Hanxiao <chenhanxiao(a)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(a)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;
We use camelCase for struct member names. Also some options might
invalidate more than one other option thus it is desirable to have this
as a NULL terminated string list of options this option invalidates.
Later on we may use this to do automatic checking for mutually exclusive
options that are now declared using macros in the code.
if (!state) {
/* determine command name */
@@ -2720,6 +2722,12 @@ vshReadlineOptionsGenerator(const char *text,
int state)
/* ignore non --option */
continue;
+ if (len == 2 && opt->type == VSH_OT_ALIAS)
+ continue;
I think we should always ignore aliases. We introduced aliases to change
command names without breaking compatibility with scripts. For human
interaction we shouldn't encourage to use deprecated and undocumented
stuff even if the user remebered that such command was possibly available.
+
+ if (exclude_option && (strstr(rl_line_buffer, exclude_option)))
+ continue;
This should then iterate the array of exclusive options.
+
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 */
As said above. Please use camelCase and turn this into the opti
};
/*
Peter