> -----Original Message----- > From: Chen Hanxiao [mailto:chenhanxiao@xxxxxxxxxxxxxx] > Sent: Thursday, October 31, 2013 8:19 AM > To: libvir-list@xxxxxxxxxx > Cc: chenhanxiao@xxxxxxxxxxxxxx > Subject: [PATCH v2]virsh: track alias option and improve error message > when option duplicates its alias > > From: Chen Hanxiao <chenhanxiao@xxxxxxxxxxxxxx> > > commit 2b172a8effa712aee97a21a64d2d02060958f9b2 allow > alias to expand to opt=value pair. > That means alias may not look alike since then. > > With this patch we will also track alias. > If we type command with one option and another marked > as its alias, we will get an error message like: > error: option '--AA' duplicates its alias '--AAA' > > Signed-off-by: Chen Hanxiao <chenhanxiao@xxxxxxxxxxxxxx> > --- > v2: do not depend on orders of options in array. > Alias could be anywhere except after the default one. > > tools/virsh.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/tools/virsh.c b/tools/virsh.c > index bad78c9..ffead84 100644 > --- a/tools/virsh.c > +++ b/tools/virsh.c > @@ -1071,6 +1071,7 @@ vshCmddefGetOption(vshControl *ctl, const > vshCmdDef *cmd, const char *name, > size_t i; > const vshCmdOptDef *ret = NULL; > char *alias = NULL; > + char *tmp_name = NULL; > > if (STREQ(name, helpopt.name)) { > return &helpopt; > @@ -1101,6 +1102,13 @@ vshCmddefGetOption(vshControl *ctl, const > vshCmdDef *cmd, const char *name, > if (VIR_STRDUP(*optstr, value + 1) < 0) > goto cleanup; > } > + tmp_name = vshMalloc(NULL, strlen(name) + 3); > + snprintf(tmp_name, strlen(name) + 3, "--%s", name); > + if (strstr(rl_line_buffer, tmp_name)) { > + vshError(ctl, _("option '--%s' duplicates its alias > '--%s'"), > + cmd->opts[i].name, name); > + goto cleanup; > + } > continue; > } > if ((*opts_seen & (1 << i)) && opt->type != VSH_OT_ARGV) { > @@ -1119,6 +1127,7 @@ vshCmddefGetOption(vshControl *ctl, const > vshCmdDef *cmd, const char *name, > cmd->name, name); > } > cleanup: > + VIR_FREE(tmp_name); > VIR_FREE(alias); > return ret; > } > -- > 1.8.2.1 ping -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list