tools: vshCmddefCheckInternals: Add parameter name to error message

If a parameter definition is invalid we can include the name of the
parameter for simpler debugging.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2020-11-12 12:04:11 +01:00
parent f2a602f5a3
commit b070332261

View File

@ -307,8 +307,8 @@ vshCmddefCheckInternals(vshControl *ctl,
case VSH_OT_STRING: case VSH_OT_STRING:
case VSH_OT_BOOL: case VSH_OT_BOOL:
if (opt->flags & VSH_OFLAG_REQ) { if (opt->flags & VSH_OFLAG_REQ) {
vshError(ctl, _("command '%s' misused VSH_OFLAG_REQ"), vshError(ctl, _("parameter '%s' of command '%s' misused VSH_OFLAG_REQ"),
cmd->name); opt->name, cmd->name);
return -1; /* neither bool nor string options can be mandatory */ return -1; /* neither bool nor string options can be mandatory */
} }
break; break;
@ -319,8 +319,8 @@ vshCmddefCheckInternals(vshControl *ctl,
char *p; char *p;
if (opt->flags || !opt->help) { if (opt->flags || !opt->help) {
vshError(ctl, _("command '%s' has incorrect alias option"), vshError(ctl, _("parameter '%s' of command '%s' has incorrect alias option"),
cmd->name); opt->name, cmd->name);
return -1; /* alias options are tracked by the original name */ return -1; /* alias options are tracked by the original name */
} }
if ((p = strchr(name, '='))) if ((p = strchr(name, '=')))
@ -334,30 +334,30 @@ vshCmddefCheckInternals(vshControl *ctl,
VIR_FREE(name); VIR_FREE(name);
/* If alias comes with value, replacement must not be bool */ /* If alias comes with value, replacement must not be bool */
if (cmd->opts[j].type == VSH_OT_BOOL) { if (cmd->opts[j].type == VSH_OT_BOOL) {
vshError(ctl, _("command '%s' has mismatched alias type"), vshError(ctl, _("alias '%s' of command '%s' has mismatched alias type"),
cmd->name); opt->name, cmd->name);
return -1; return -1;
} }
} }
if (!cmd->opts[j].name) { if (!cmd->opts[j].name) {
vshError(ctl, _("command '%s' has missing alias option"), vshError(ctl, _("alias '%s' of command '%s' has missing alias option"),
cmd->name); opt->name, cmd->name);
return -1; /* alias option must map to a later option name */ return -1; /* alias option must map to a later option name */
} }
} }
break; break;
case VSH_OT_ARGV: case VSH_OT_ARGV:
if (cmd->opts[i + 1].name) { if (cmd->opts[i + 1].name) {
vshError(ctl, _("command '%s' does not list argv option last"), vshError(ctl, _("parameter '%s' of command '%s' must be listed last"),
cmd->name); opt->name, cmd->name);
return -1; /* argv option must be listed last */ return -1; /* argv option must be listed last */
} }
break; break;
case VSH_OT_DATA: case VSH_OT_DATA:
if (!(opt->flags & VSH_OFLAG_REQ)) { if (!(opt->flags & VSH_OFLAG_REQ)) {
vshError(ctl, _("command '%s' has non-required VSH_OT_DATA"), vshError(ctl, _("parameter '%s' of command '%s' must use VSH_OFLAG_REQ flag"),
cmd->name); opt->name, cmd->name);
return -1; /* OT_DATA should always be required. */ return -1; /* OT_DATA should always be required. */
} }
break; break;