vsh: Replace 'VSH_OFLAG_EMPTY_OK' bitwise flag with a separate struct member

Replace the last bitwise flag with a separate member.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2024-03-11 13:17:50 +01:00
parent 8e39542a03
commit 4b44113d7b
6 changed files with 12 additions and 12 deletions

View File

@ -864,8 +864,8 @@ static const vshCmdOptDef opts_domblkstat[] = {
VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE),
{.name = "device",
.type = VSH_OT_STRING,
.flags = VSH_OFLAG_EMPTY_OK,
.positional = true,
.allowEmpty = true,
.completer = virshDomainDiskTargetCompleter,
.help = N_("block device")
},

View File

@ -422,7 +422,7 @@ static const vshCmdOptDef opts_attach_disk[] = {
.type = VSH_OT_STRING,
.positional = true,
.required = true,
.flags = VSH_OFLAG_EMPTY_OK,
.allowEmpty = true,
.help = N_("source of disk device or name of network disk")
},
{.name = "target",
@ -6838,7 +6838,7 @@ static const vshCmdOptDef opts_vcpupin[] = {
{.name = "cpulist",
.type = VSH_OT_STRING,
.unwanted_positional = true,
.flags = VSH_OFLAG_EMPTY_OK,
.allowEmpty = true,
.completer = virshDomainCpulistCompleter,
.help = N_("host cpu number(s) to set, or omit option to query")
},
@ -7047,7 +7047,7 @@ static const vshCmdOptDef opts_emulatorpin[] = {
{.name = "cpulist",
.type = VSH_OT_STRING,
.unwanted_positional = true,
.flags = VSH_OFLAG_EMPTY_OK,
.allowEmpty = true,
.completer = virshDomainCpulistCompleter,
.help = N_("host cpu number(s) to set, or omit option to query")
},

View File

@ -246,7 +246,7 @@ static const vshCmdOptDef opts_connect[] = {
{.name = "name",
.type = VSH_OT_STRING,
.positional = true,
.flags = VSH_OFLAG_EMPTY_OK,
.allowEmpty = true,
.completer = virshCompleteEmpty,
.help = N_("hypervisor connection URI")
},

View File

@ -255,7 +255,7 @@ static const vshCmdOptDef opts_connect[] = {
{.name = "name",
.type = VSH_OT_STRING,
.positional = true,
.flags = VSH_OFLAG_EMPTY_OK,
.allowEmpty = true,
.help = N_("daemon's admin server connection URI")
},
{.name = NULL}
@ -961,7 +961,7 @@ static const vshCmdOptDef opts_daemon_log_filters[] = {
.type = VSH_OT_STRING,
.positional = true,
.help = N_("redefine the existing set of logging filters"),
.flags = VSH_OFLAG_EMPTY_OK
.allowEmpty = true
},
{.name = NULL}
};
@ -1044,7 +1044,7 @@ static const vshCmdOptDef opts_daemon_log_outputs[] = {
.type = VSH_OT_STRING,
.positional = true,
.help = N_("redefine the existing set of logging outputs"),
.flags = VSH_OFLAG_EMPTY_OK
.allowEmpty = true
},
{.name = NULL}
};

View File

@ -1030,7 +1030,7 @@ vshCommandOptStringQuiet(vshControl *ctl G_GNUC_UNUSED, const vshCmd *cmd,
if ((ret = vshCommandOpt(cmd, name, &arg, true)) <= 0)
return ret;
if (!*arg->data && !(arg->def->flags & VSH_OFLAG_EMPTY_OK))
if (!arg->def->allowEmpty && *arg->data == '\0')
return -1;
*value = arg->data;
return 1;
@ -1069,7 +1069,7 @@ vshCommandOptStringReq(vshControl *ctl,
/* this should not be propagated here, just to be sure */
if (ret == -1)
error = N_("Mandatory option not present");
else if (arg && !*arg->data && !(arg->def->flags & VSH_OFLAG_EMPTY_OK))
else if (arg && *arg->data == '\0' && !arg->def->allowEmpty)
error = N_("Option argument is empty");
if (error) {
@ -3394,7 +3394,7 @@ const vshCmdOptDef opts_complete[] = {
{.name = "string",
.type = VSH_OT_ARGV,
.positional = true,
.flags = VSH_OFLAG_EMPTY_OK,
.allowEmpty = true,
.help = N_("partial string to autocomplete")
},
{.name = NULL}

View File

@ -98,7 +98,6 @@ typedef enum {
*/
enum {
VSH_OFLAG_NONE = 0, /* without flags */
VSH_OFLAG_EMPTY_OK = (1 << 1), /* empty string option allowed */
};
/* forward declarations */
@ -140,6 +139,7 @@ struct _vshCmdOptDef {
bool unwanted_positional;
unsigned int flags; /* flags */
bool allowEmpty; /* allow empty string */
const char *help; /* non-NULL help string; or for VSH_OT_ALIAS
* the name of a later public option */
vshCompleter completer; /* option completer */