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 committed 2024-03-13 15:02:52 +01:00
1 parent 162b184d0e
commit ac150162fd
15 files changed
+283 -4

No files matched your search

+22
View File
@@ -359,6 +359,8 @@ static const vshCmdInfo info_srv_threadpool_info = {
static const vshCmdOptDef opts_srv_threadpool_info[] = {
{.name = "server",
.type = VSH_OT_DATA,
.positional = true,
.required = true,
.flags = VSH_OFLAG_REQ,
.completer = vshAdmServerCompleter,
.help = N_("Server to retrieve threadpool attributes from."),
@@ -416,6 +418,8 @@ static const vshCmdInfo info_srv_threadpool_set = {
static const vshCmdOptDef opts_srv_threadpool_set[] = {
{.name = "server",
.type = VSH_OT_DATA,
.positional = true,
.required = true,
.flags = VSH_OFLAG_REQ,
.completer = vshAdmServerCompleter,
.help = N_("Server to alter threadpool attributes on."),
@@ -517,6 +521,8 @@ static const vshCmdInfo info_srv_clients_list = {
static const vshCmdOptDef opts_srv_clients_list[] = {
{.name = "server",
.type = VSH_OT_DATA,
.positional = true,
.required = true,
.flags = VSH_OFLAG_REQ,
.completer = vshAdmServerCompleter,
.help = N_("server which to list connected clients from"),
@@ -599,12 +605,16 @@ static const vshCmdInfo info_client_info = {
static const vshCmdOptDef opts_client_info[] = {
{.name = "server",
.type = VSH_OT_DATA,
.positional = true,
.required = true,
.flags = VSH_OFLAG_REQ,
.completer = vshAdmServerCompleter,
.help = N_("server to which <client> is connected to"),
},
{.name = "client",
.type = VSH_OT_DATA,
.positional = true,
.required = true,
.flags = VSH_OFLAG_REQ,
.help = N_("client which to retrieve identity information for"),
},
@@ -681,12 +691,16 @@ static const vshCmdInfo info_client_disconnect = {
static const vshCmdOptDef opts_client_disconnect[] = {
{.name = "server",
.type = VSH_OT_DATA,
.positional = true,
.required = true,
.flags = VSH_OFLAG_REQ,
.completer = vshAdmServerCompleter,
.help = N_("server which the client is currently connected to"),
},
{.name = "client",
.type = VSH_OT_INT,
.positional = true,
.required = true,
.flags = VSH_OFLAG_REQ,
.help = N_("client which to disconnect, specified by ID"),
},
@@ -742,6 +756,8 @@ static const vshCmdInfo info_srv_clients_info = {
static const vshCmdOptDef opts_srv_clients_info[] = {
{.name = "server",
.type = VSH_OT_DATA,
.positional = true,
.required = true,
.flags = VSH_OFLAG_REQ,
.completer = vshAdmServerCompleter,
.help = N_("Server to retrieve the client limits from."),
@@ -796,6 +812,8 @@ static const vshCmdInfo info_srv_clients_set = {
static const vshCmdOptDef opts_srv_clients_set[] = {
{.name = "server",
.type = VSH_OT_DATA,
.positional = true,
.required = true,
.flags = VSH_OFLAG_REQ,
.completer = vshAdmServerCompleter,
.help = N_("Server to alter the client-related configuration limits on."),
@@ -893,6 +911,8 @@ static const vshCmdInfo info_srv_update_tls_file = {
static const vshCmdOptDef opts_srv_update_tls_file[] = {
{.name = "server",
.type = VSH_OT_DATA,
.positional = true,
.required = true,
.flags = VSH_OFLAG_REQ,
.help = N_("Available servers on a daemon. "
"Currently only supports 'libvirtd' or 'virtproxyd'.")
@@ -991,6 +1011,8 @@ static const vshCmdInfo info_daemon_log_outputs = {
static const vshCmdOptDef opts_daemon_timeout[] = {
{.name = "timeout",
.type = VSH_OT_INT,
.positional = true,
.required = true,
.help = N_("number of seconds the daemon will run without any active connection"),
.flags = VSH_OFLAG_REQ | VSH_OFLAG_REQ_OPT
},