vsh: Annotate 'required' and 'positional' arguments explicitly

Add 'positional' and 'required' fields to vshCmdOptDef, which will
explicitly track the two properties of arguments.

To ensure that we have proper coverage, add checks to
vshCmddefCheckInternals validating the state of the above flags by
infering it from existing data.

This conversion will allow us:
 - remove VSH_OT_DATA in favor of VSH_OT_STRING
 - use VSH_OT_INT when required both as positional and non-positional
 - properly annotate which VSH_OT_ARGV are positional and which are not
   (currently inferred by whether an previous positional option exists)

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-05 15:07:47 +01:00
parent 162b184d0e
commit ac150162fd
15 changed files with 283 additions and 4 deletions

View File

@@ -57,6 +57,8 @@
#define VIRSH_COMMON_OPT_VOL_NAME(_helpstr) \
{.name = "vol", \
.type = VSH_OT_DATA, \
.positional = true, \
.required = true, \
.flags = VSH_OFLAG_REQ, \
.help = _helpstr, \
.completer = virshStorageVolNameCompleter, \
@@ -65,6 +67,8 @@
#define VIRSH_COMMON_OPT_VOL_KEY(_helpstr) \
{.name = "vol", \
.type = VSH_OT_DATA, \
.positional = true, \
.required = true, \
.flags = VSH_OFLAG_REQ, \
.help = _helpstr, \
.completer = virshStorageVolKeyCompleter, \
@@ -173,12 +177,16 @@ static const vshCmdOptDef opts_vol_create_as[] = {
VIRSH_COMMON_OPT_POOL_NAME,
{.name = "name",
.type = VSH_OT_DATA,
.positional = true,
.required = true,
.flags = VSH_OFLAG_REQ,
.completer = virshCompleteEmpty,
.help = N_("name of the volume")
},
{.name = "capacity",
.type = VSH_OT_DATA,
.positional = true,
.required = true,
.flags = VSH_OFLAG_REQ,
.completer = virshCompleteEmpty,
.help = N_("size of the vol, as scaled integer (default bytes)")
@@ -520,6 +528,8 @@ static const vshCmdOptDef opts_vol_clone[] = {
VIRSH_COMMON_OPT_VOL_FULL,
{.name = "newname",
.type = VSH_OT_DATA,
.positional = true,
.required = true,
.flags = VSH_OFLAG_REQ,
.completer = virshCompleteEmpty,
.help = N_("clone name")
@@ -1024,6 +1034,8 @@ static const vshCmdOptDef opts_vol_resize[] = {
VIRSH_COMMON_OPT_VOL_FULL,
{.name = "capacity",
.type = VSH_OT_DATA,
.positional = true,
.required = true,
.flags = VSH_OFLAG_REQ,
.completer = virshCompleteEmpty,
.help = N_("new capacity for the vol, as scaled integer (default bytes)")