From: Peter Krempa Date: Mon, 4 Mar 2024 14:40:40 +0000 (+0100) Subject: vsh: Add VSH_OT_NONE option type to catch programming errors X-Git-Tag: v10.2.0-rc1~86 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3fcae7a028d99c446c378a6a96d860e175463f06;p=thirdparty%2Flibvirt.git vsh: Add VSH_OT_NONE option type to catch programming errors Add a check that the default 0 assignment will not mean that an option is considered to be VSH_OT_BOOL. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- diff --git a/tools/vsh.c b/tools/vsh.c index 2cda6b575c..ad72b91d6c 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -335,6 +335,11 @@ vshCmddefCheckInternals(vshControl *ctl, virBufferStrcat(&complbuf, opt->name, ", ", NULL); switch (opt->type) { + case VSH_OT_NONE: + vshError(ctl, "invalid type 'NONE' of option '%s' of command '%s'", + opt->name, cmd->name); + return -1; + case VSH_OT_BOOL: if (opt->completer || opt->completer_flags) { vshError(ctl, "bool parameter '%s' of command '%s' has completer set", @@ -671,6 +676,7 @@ vshCmddefHelp(const vshCmdDef *def) } break; case VSH_OT_ALIAS: + case VSH_OT_NONE: /* aliases are intentionally undocumented */ continue; } @@ -713,6 +719,7 @@ vshCmddefHelp(const vshCmdDef *def) opt->name); break; case VSH_OT_ALIAS: + case VSH_OT_NONE: continue; } diff --git a/tools/vsh.h b/tools/vsh.h index f4152c8294..c49bed9d59 100644 --- a/tools/vsh.h +++ b/tools/vsh.h @@ -85,6 +85,7 @@ typedef enum { * vshCmdOptType - command option type */ typedef enum { + VSH_OT_NONE = 0, /* cannary to catch programming errors */ VSH_OT_BOOL, /* optional boolean option */ VSH_OT_STRING, /* optional string option */ VSH_OT_INT, /* optional or mandatory int option */