/*
* Command Option Flags
*/
-#define VSH_OFLAG_NONE 0 /* without flags */
-#define VSH_OFLAG_REQ (1 << 1) /* option required */
+enum {
+ VSH_OFLAG_NONE = 0, /* without flags */
+ VSH_OFLAG_REQ = (1 << 0), /* option required */
+ VSH_OFLAG_EMPTY_OK = (1 << 1), /* empty string option allowed */
+};
/* dummy */
typedef struct __vshControl vshControl;
};
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")},
{NULL, 0, 0, NULL}
};
int ret = 0;
if (arg && arg->data) {
- ret = -1;
- if (*arg->data) {
- if (value) {
- *value = arg->data;
- ret = 1;
- }
+ if (*arg->data
+ || (arg->def && (arg->def->flag & VSH_OFLAG_EMPTY_OK))) {
+ *value = arg->data;
+ ret = 1;
} else if (arg->def && ((arg->def->flag) & VSH_OFLAG_REQ)) {
vshError(NULL, _("Missing required option '%s'"), name);
+ ret = -1;
+ } else {
+ /* Treat "--option ''" as if option had not been specified. */
+ ret = 0;
}
}