提交 86157b59 编写于 作者: C Cole Robinson

virsh: make 'help' command ignore spurious options

Similar to the previous patch, prepending 'help' to a partial
command string doesn't cut us any slack.

$ virsh help pool-define-as --name foo --type dir
error: command 'help' doesn't support option --name

This patch adds a few hacks to make 'help' ignore everything after the
first data bit, so the above command shows help output for pool-define-as.
上级 d2f97139
...@@ -1219,8 +1219,10 @@ vshCmddefGetOption(vshControl *ctl, const vshCmdDef *cmd, const char *name, ...@@ -1219,8 +1219,10 @@ vshCmddefGetOption(vshControl *ctl, const vshCmdDef *cmd, const char *name,
} }
} }
vshError(ctl, _("command '%s' doesn't support option --%s"), if (STRNEQ(cmd->name, "help")) {
cmd->name, name); vshError(ctl, _("command '%s' doesn't support option --%s"),
cmd->name, name);
}
return NULL; return NULL;
} }
...@@ -1987,9 +1989,12 @@ vshCommandParse(vshControl *ctl, vshCommandParser *parser) ...@@ -1987,9 +1989,12 @@ vshCommandParse(vshControl *ctl, vshCommandParser *parser)
*optstr = '\0'; /* convert the '=' to '\0' */ *optstr = '\0'; /* convert the '=' to '\0' */
optstr = vshStrdup(ctl, optstr + 1); optstr = vshStrdup(ctl, optstr + 1);
} }
/* Special case 'help' to ignore all spurious options */
if (!(opt = vshCmddefGetOption(ctl, cmd, tkdata + 2, if (!(opt = vshCmddefGetOption(ctl, cmd, tkdata + 2,
&opts_seen, &opt_index))) { &opts_seen, &opt_index))) {
VIR_FREE(optstr); VIR_FREE(optstr);
if (STREQ(cmd->name, "help"))
continue;
goto syntaxError; goto syntaxError;
} }
VIR_FREE(tkdata); VIR_FREE(tkdata);
...@@ -2027,8 +2032,10 @@ vshCommandParse(vshControl *ctl, vshCommandParser *parser) ...@@ -2027,8 +2032,10 @@ vshCommandParse(vshControl *ctl, vshCommandParser *parser)
continue; continue;
} else { } else {
get_data: get_data:
/* Special case 'help' to ignore spurious data */
if (!(opt = vshCmddefGetData(cmd, &opts_need_arg, if (!(opt = vshCmddefGetData(cmd, &opts_need_arg,
&opts_seen))) { &opts_seen)) &&
STRNEQ(cmd->name, "help")) {
vshError(ctl, _("unexpected data '%s'"), tkdata); vshError(ctl, _("unexpected data '%s'"), tkdata);
goto syntaxError; goto syntaxError;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册