mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +00:00
vshCommandOpt: Allow caller avoiding assert()
In the future, completer callbacks will receive partially parsed command (and thus possibly incomplete). However, we still want them to use command options fetching APIs we already have (e.g. vshCommandOpt*()) and at the same time don't report any errors (nor call any asserts). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
69ebc64518
commit
a26ff63ae4
14
tools/vsh.c
14
tools/vsh.c
@ -815,8 +815,8 @@ vshCommandFree(vshCmd *cmd)
|
|||||||
* to the option if found, 0 with *OPT set to NULL if the name is
|
* to the option if found, 0 with *OPT set to NULL if the name is
|
||||||
* valid and the option is not required, -1 with *OPT set to NULL if
|
* valid and the option is not required, -1 with *OPT set to NULL if
|
||||||
* the option is required but not present, and assert if NAME is not
|
* the option is required but not present, and assert if NAME is not
|
||||||
* valid (which indicates a programming error). No error messages are
|
* valid (which indicates a programming error) unless cmd->skipChecks
|
||||||
* issued if a value is returned.
|
* is set. No error messages are issued if a value is returned.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
vshCommandOpt(const vshCmd *cmd, const char *name, vshCmdOpt **opt,
|
vshCommandOpt(const vshCmd *cmd, const char *name, vshCmdOpt **opt,
|
||||||
@ -828,15 +828,19 @@ vshCommandOpt(const vshCmd *cmd, const char *name, vshCmdOpt **opt,
|
|||||||
|
|
||||||
/* See if option is valid and/or required. */
|
/* See if option is valid and/or required. */
|
||||||
*opt = NULL;
|
*opt = NULL;
|
||||||
while (valid) {
|
|
||||||
assert(valid->name);
|
if (!cmd->skipChecks) {
|
||||||
|
while (valid && valid->name) {
|
||||||
if (STREQ(name, valid->name))
|
if (STREQ(name, valid->name))
|
||||||
break;
|
break;
|
||||||
valid++;
|
valid++;
|
||||||
}
|
}
|
||||||
assert(!needData || valid->type != VSH_OT_BOOL);
|
|
||||||
|
assert(valid && (!needData || valid->type != VSH_OT_BOOL));
|
||||||
|
|
||||||
if (valid->flags & VSH_OFLAG_REQ)
|
if (valid->flags & VSH_OFLAG_REQ)
|
||||||
ret = -1;
|
ret = -1;
|
||||||
|
}
|
||||||
|
|
||||||
/* See if option is present on command line. */
|
/* See if option is present on command line. */
|
||||||
while (candidate) {
|
while (candidate) {
|
||||||
|
@ -189,6 +189,7 @@ struct _vshCmd {
|
|||||||
const vshCmdDef *def; /* command definition */
|
const vshCmdDef *def; /* command definition */
|
||||||
vshCmdOpt *opts; /* list of command arguments */
|
vshCmdOpt *opts; /* list of command arguments */
|
||||||
vshCmd *next; /* next command */
|
vshCmd *next; /* next command */
|
||||||
|
bool skipChecks; /* skip validity checks when retrieving opts */
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user