};
static const vshCmdOptDef *
vshCmddefGetOption(vshControl *ctl, const vshCmdDef *cmd, const char *name,
- uint64_t *opts_seen, int *opt_index, char **optstr)
+ uint64_t *opts_seen, int *opt_index, char **optstr,
+ bool report)
{
size_t i;
const vshCmdOptDef *ret = NULL;
if ((value = strchr(name, '='))) {
*value = '\0';
if (*optstr) {
- vshError(ctl, _("invalid '=' after option --%s"),
- opt->name);
+ if (report)
+ vshError(ctl, _("invalid '=' after option --%s"),
+ opt->name);
goto cleanup;
}
if (VIR_STRDUP(*optstr, value + 1) < 0)
continue;
}
if ((*opts_seen & (1ULL << i)) && opt->type != VSH_OT_ARGV) {
- vshError(ctl, _("option --%s already seen"), name);
+ if (report)
+ vshError(ctl, _("option --%s already seen"), name);
goto cleanup;
}
*opts_seen |= 1ULL << i;
}
}
- if (STRNEQ(cmd->name, "help")) {
+ if (STRNEQ(cmd->name, "help") && report) {
vshError(ctl, _("command '%s' doesn't support option --%s"),
cmd->name, name);
}
typedef struct _vshCommandParser vshCommandParser;
struct _vshCommandParser {
vshCommandToken(*getNextArg)(vshControl *, vshCommandParser *,
- char **);
+ char **, bool);
/* vshCommandStringGetArg() */
char *pos;
/* vshCommandArgvGetArg() */
const vshCmdOptDef *opt = NULL;
tkdata = NULL;
- tk = parser->getNextArg(ctl, parser, &tkdata);
+ tk = parser->getNextArg(ctl, parser, &tkdata, true);
if (tk == VSH_TK_ERROR)
goto syntaxError;
/* Special case 'help' to ignore all spurious options */
if (!(opt = vshCmddefGetOption(ctl, cmd, tkdata + 2,
&opts_seen, &opt_index,
- &optstr))) {
+ &optstr, true))) {
VIR_FREE(optstr);
if (STREQ(cmd->name, "help"))
continue;
if (optstr)
tkdata = optstr;
else
- tk = parser->getNextArg(ctl, parser, &tkdata);
+ tk = parser->getNextArg(ctl, parser, &tkdata, true);
if (tk == VSH_TK_ERROR)
goto syntaxError;
if (tk != VSH_TK_ARG) {
*/
static vshCommandToken ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
-vshCommandArgvGetArg(vshControl *ctl, vshCommandParser *parser, char **res)
+vshCommandArgvGetArg(vshControl *ctl, vshCommandParser *parser, char **res,
+ bool report ATTRIBUTE_UNUSED)
{
if (parser->arg_pos == parser->arg_end) {
*res = NULL;
*/
static vshCommandToken ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
-vshCommandStringGetArg(vshControl *ctl, vshCommandParser *parser, char **res)
+vshCommandStringGetArg(vshControl *ctl, vshCommandParser *parser, char **res,
+ bool report)
{
bool single_quote = false;
bool double_quote = false;
*/
p++;
if (*p == '\0') {
- vshError(ctl, "%s", _("dangling \\"));
+ if (report)
+ vshError(ctl, "%s", _("dangling \\"));
return VSH_TK_ERROR;
}
} else if (!single_quote && *p == '"') { /* double quote */
sz++;
}
if (double_quote) {
- vshError(ctl, "%s", _("missing \""));
+ if (report)
+ vshError(ctl, "%s", _("missing \""));
return VSH_TK_ERROR;
}