mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
virsh: allow empty string arguments
"virsh connect ''" should try to connect to the default connection, but the previous patch made it issue a warning about an invalid URI. * tools/virsh.c (VSH_OFLAG_EMPTY_OK): New option flag. (vshCommandOptString): Per the declaration, value is required to be non-NULL. Honor new flag. (opts_connect): Allow empty string connection.
This commit is contained in:
parent
ce81bc5ce8
commit
6eaa4ee41b
@ -152,8 +152,11 @@ typedef enum {
|
|||||||
/*
|
/*
|
||||||
* Command Option Flags
|
* Command Option Flags
|
||||||
*/
|
*/
|
||||||
#define VSH_OFLAG_NONE 0 /* without flags */
|
enum {
|
||||||
#define VSH_OFLAG_REQ (1 << 1) /* option required */
|
VSH_OFLAG_NONE = 0, /* without flags */
|
||||||
|
VSH_OFLAG_REQ = (1 << 0), /* option required */
|
||||||
|
VSH_OFLAG_EMPTY_OK = (1 << 1), /* empty string option allowed */
|
||||||
|
};
|
||||||
|
|
||||||
/* dummy */
|
/* dummy */
|
||||||
typedef struct __vshControl vshControl;
|
typedef struct __vshControl vshControl;
|
||||||
@ -685,7 +688,8 @@ static const vshCmdInfo info_connect[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static const vshCmdOptDef opts_connect[] = {
|
static const vshCmdOptDef opts_connect[] = {
|
||||||
{"name", VSH_OT_DATA, 0, N_("hypervisor connection URI")},
|
{"name", VSH_OT_DATA, VSH_OFLAG_EMPTY_OK,
|
||||||
|
N_("hypervisor connection URI")},
|
||||||
{"readonly", VSH_OT_BOOL, 0, N_("read-only connection")},
|
{"readonly", VSH_OT_BOOL, 0, N_("read-only connection")},
|
||||||
{NULL, 0, 0, NULL}
|
{NULL, 0, 0, NULL}
|
||||||
};
|
};
|
||||||
@ -10993,14 +10997,16 @@ vshCommandOptString(const vshCmd *cmd, const char *name, const char **value)
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if (arg && arg->data) {
|
if (arg && arg->data) {
|
||||||
ret = -1;
|
if (*arg->data
|
||||||
if (*arg->data) {
|
|| (arg->def && (arg->def->flag & VSH_OFLAG_EMPTY_OK))) {
|
||||||
if (value) {
|
*value = arg->data;
|
||||||
*value = arg->data;
|
ret = 1;
|
||||||
ret = 1;
|
|
||||||
}
|
|
||||||
} else if (arg->def && ((arg->def->flag) & VSH_OFLAG_REQ)) {
|
} else if (arg->def && ((arg->def->flag) & VSH_OFLAG_REQ)) {
|
||||||
vshError(NULL, _("Missing required option '%s'"), name);
|
vshError(NULL, _("Missing required option '%s'"), name);
|
||||||
|
ret = -1;
|
||||||
|
} else {
|
||||||
|
/* Treat "--option ''" as if option had not been specified. */
|
||||||
|
ret = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user