vsh: Move option assignment debugging from vshCommandParse to vshCmdOptAssign

As we now have a centralized point to assign values to options move the
debugging logic there.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2024-04-17 14:06:38 +02:00
parent 166fe3c7b5
commit c27070f738

View File

@ -528,9 +528,11 @@ vshCmdGetOption(vshControl *ctl,
static void static void
vshCmdOptAssign(vshCmd *cmd, vshCmdOptAssign(vshControl *ctl,
vshCmd *cmd,
vshCmdOpt *opt, vshCmdOpt *opt,
const char *val) const char *val,
bool report)
{ {
cmd->lastopt = opt; cmd->lastopt = opt;
@ -539,14 +541,28 @@ vshCmdOptAssign(vshCmd *cmd,
switch (opt->def->type) { switch (opt->def->type) {
case VSH_OT_BOOL: case VSH_OT_BOOL:
/* nothing to do */ /* nothing to do */
if (report) {
vshDebug(ctl, VSH_ERR_INFO, "%s: %s(bool)\n",
cmd->def->name, opt->def->name);
}
break; break;
case VSH_OT_STRING: case VSH_OT_STRING:
case VSH_OT_INT: case VSH_OT_INT:
if (report) {
vshDebug(ctl, VSH_ERR_INFO, "%s: %s(optdata): %s\n",
cmd->def->name, opt->def->name, NULLSTR(val));
}
opt->data = g_strdup(val); opt->data = g_strdup(val);
break; break;
case VSH_OT_ARGV: case VSH_OT_ARGV:
if (report) {
vshDebug(ctl, VSH_ERR_INFO, "%s: %s(argv: %zu): %s\n",
cmd->def->name, opt->def->name, opt->nargv, NULLSTR(val));
}
VIR_EXPAND_N(opt->argv, opt->nargv, 2); VIR_EXPAND_N(opt->argv, opt->nargv, 2);
/* VIR_EXPAND_N updates count */ /* VIR_EXPAND_N updates count */
opt->nargv--; opt->nargv--;
@ -1538,7 +1554,7 @@ vshCommandParse(vshControl *ctl, vshCommandParser *parser, vshCmd **partial)
goto syntaxError; goto syntaxError;
if (tk != VSH_TK_ARG) { if (tk != VSH_TK_ARG) {
if (partial) { if (partial) {
vshCmdOptAssign(cmd, opt, tkdata); vshCmdOptAssign(ctl, cmd, opt, tkdata, !partial);
VIR_FREE(tkdata); VIR_FREE(tkdata);
} else { } else {
vshError(ctl, vshError(ctl,
@ -1576,15 +1592,8 @@ vshCommandParse(vshControl *ctl, vshCommandParser *parser, vshCmd **partial)
} }
if (opt) { if (opt) {
vshCmdOptAssign(cmd, opt, tkdata); vshCmdOptAssign(ctl, cmd, opt, tkdata, !partial);
VIR_FREE(tkdata); VIR_FREE(tkdata);
if (!partial)
vshDebug(ctl, VSH_ERR_INFO, "%s: %s(%s): %s\n",
cmd->def->name,
opt->def->name,
opt->def->type != VSH_OT_BOOL ? _("optdata") : _("bool"),
opt->def->type != VSH_OT_BOOL ? opt->data : _("(none)"));
} }
} }