提交 846d3b58 编写于 作者: M Michal Privoznik

vshCommandOpt: Do more checking if skipChecks is set

Currently if cmd->skipChecks is set (done only from completers)
some basic checks are skipped because we're working over
partially parsed command. See a26ff63a for more detailed
explanation. Anyway, the referenced commit was too aggressive in
disabling checks and effectively returned success even in clear
case of failure. For instance:

  # domif-getlink --interface <TAB><TAB>

causes virshDomainInterfaceCompleter() to be called, which calls
virshDomainGetXML() which eventually calls
vshCommandOptStringReq(.., name = "domain"); The --domain
argument is required for the command and if not present -1 should
be returned to tell the caller the argument was not found. Well,
zero is returned meaning the argument was not found but it's not
required either.
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
上级 98c9c304
......@@ -817,18 +817,17 @@ vshCommandOpt(const vshCmd *cmd, const char *name, vshCmdOpt **opt,
/* See if option is valid and/or required. */
*opt = NULL;
if (!cmd->skipChecks) {
while (valid && valid->name) {
if (STREQ(name, valid->name))
break;
valid++;
}
while (valid && valid->name) {
if (STREQ(name, valid->name))
break;
valid++;
}
if (!cmd->skipChecks)
assert(valid && (!needData || valid->type != VSH_OT_BOOL));
if (valid->flags & VSH_OFLAG_REQ)
ret = -1;
}
if (valid && valid->flags & VSH_OFLAG_REQ)
ret = -1;
/* See if option is present on command line. */
while (candidate) {
......@@ -1065,7 +1064,8 @@ vshCommandOptStringReq(vshControl *ctl,
error = N_("Option argument is empty");
if (error) {
vshError(ctl, _("Failed to get option '%s': %s"), name, _(error));
if (!cmd->skipChecks)
vshError(ctl, _("Failed to get option '%s': %s"), name, _(error));
return -1;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册