mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 07:59:00 +00:00
vsh: Make self-test more robust
There are couple of limitations when it comes to option types and flags for the options. For instance, VSH_OT_STRING cannot have VSH_OFLAG_REQ set (commit c7543a728). For some reason this is checked in vshCmddefHelp() but not in vshCmddefCheckInternals(). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
0d110277c0
commit
6dc5490141
44
tools/vsh.c
44
tools/vsh.c
@ -363,12 +363,15 @@ vshCmddefCheckInternals(const vshCmdDef *cmd)
|
|||||||
|
|
||||||
if (i > 63)
|
if (i > 63)
|
||||||
return -1; /* too many options */
|
return -1; /* too many options */
|
||||||
if (opt->type == VSH_OT_BOOL) {
|
|
||||||
|
switch (opt->type) {
|
||||||
|
case VSH_OT_STRING:
|
||||||
|
case VSH_OT_BOOL:
|
||||||
if (opt->flags & VSH_OFLAG_REQ)
|
if (opt->flags & VSH_OFLAG_REQ)
|
||||||
return -1; /* bool options can't be mandatory */
|
return -1; /* nor bool nor string options can't be mandatory */
|
||||||
continue;
|
break;
|
||||||
}
|
|
||||||
if (opt->type == VSH_OT_ALIAS) {
|
case VSH_OT_ALIAS: {
|
||||||
size_t j;
|
size_t j;
|
||||||
char *name = (char *)opt->help; /* cast away const */
|
char *name = (char *)opt->help; /* cast away const */
|
||||||
char *p;
|
char *p;
|
||||||
@ -391,10 +394,21 @@ vshCmddefCheckInternals(const vshCmdDef *cmd)
|
|||||||
}
|
}
|
||||||
if (!cmd->opts[j].name)
|
if (!cmd->opts[j].name)
|
||||||
return -1; /* alias option must map to a later option name */
|
return -1; /* alias option must map to a later option name */
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
if (opt->type == VSH_OT_ARGV && cmd->opts[i + 1].name)
|
break;
|
||||||
return -1; /* argv option must be listed last */
|
case VSH_OT_ARGV:
|
||||||
|
if (cmd->opts[i + 1].name)
|
||||||
|
return -1; /* argv option must be listed last */
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VSH_OT_DATA:
|
||||||
|
if (!(opt->flags & VSH_OFLAG_REQ))
|
||||||
|
return -1; /* OT_DATA should always be required. */
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VSH_OT_INT:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -733,23 +747,9 @@ vshCmddefHelp(vshControl *ctl, const char *cmdname)
|
|||||||
: _("--%s <number>"), opt->name);
|
: _("--%s <number>"), opt->name);
|
||||||
break;
|
break;
|
||||||
case VSH_OT_STRING:
|
case VSH_OT_STRING:
|
||||||
/* OT_STRING should never be VSH_OFLAG_REQ */
|
|
||||||
if (opt->flags & VSH_OFLAG_REQ) {
|
|
||||||
vshError(ctl,
|
|
||||||
_("internal error: bad options in command: '%s'"),
|
|
||||||
def->name);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
snprintf(buf, sizeof(buf), _("--%s <string>"), opt->name);
|
snprintf(buf, sizeof(buf), _("--%s <string>"), opt->name);
|
||||||
break;
|
break;
|
||||||
case VSH_OT_DATA:
|
case VSH_OT_DATA:
|
||||||
/* OT_DATA should always be VSH_OFLAG_REQ */
|
|
||||||
if (!(opt->flags & VSH_OFLAG_REQ)) {
|
|
||||||
vshError(ctl,
|
|
||||||
_("internal error: bad options in command: '%s'"),
|
|
||||||
def->name);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
snprintf(buf, sizeof(buf), _("[--%s] <string>"),
|
snprintf(buf, sizeof(buf), _("[--%s] <string>"),
|
||||||
opt->name);
|
opt->name);
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user