vsh: Introduce annotation for vsh options which are unexpectedly parsed positionally

Based on the rationale in previous commit, all commands which were
parsed as positional but not documented as such will be annotated with
this flag.

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-13 22:31:20 +01:00
parent 348010ac93
commit d226a2cd70
2 changed files with 17 additions and 2 deletions

View File

@ -334,7 +334,8 @@ vshCmddefCheckInternals(vshControl *ctl,
case VSH_OT_ARGV:
if (brokenPositionals == 0 ||
brokenPositionals == opt->type) {
if (!(opt->flags & VSH_OFLAG_REQ_OPT) && !opt->positional)
if (!(opt->flags & VSH_OFLAG_REQ_OPT) &&
!(opt->positional || opt->unwanted_positional))
virBufferStrcat(&posbuf, opt->name, ", ", NULL);
}
break;
@ -363,6 +364,12 @@ vshCmddefCheckInternals(vshControl *ctl,
return -1;
}
if (opt->unwanted_positional && opt->positional) {
vshError(ctl, "unwanted_positional flag of argument '%s' of command '%s' must not be used together with positional",
opt->name, cmd->name);
return -1;
}
switch (opt->type) {
case VSH_OT_NONE:
vshError(ctl, "invalid type 'NONE' of option '%s' of command '%s'",
@ -376,7 +383,7 @@ vshCmddefCheckInternals(vshControl *ctl,
return -1;
}
if (opt->positional) {
if (opt->positional || opt->unwanted_positional) {
vshError(ctl, "boolean parameter '%s' of command '%s' must not be positional",
opt->name, cmd->name);
return -1;
@ -397,6 +404,7 @@ vshCmddefCheckInternals(vshControl *ctl,
if (opt->required ||
opt->positional ||
opt->unwanted_positional ||
opt->completer ||
opt->flags ||
!opt->help) {

View File

@ -133,6 +133,13 @@ struct _vshCmdOptDef {
vshCmdOptType type; /* option type */
bool required; /* option is required */
bool positional; /* option is a positional option (not requiring '--optionname') */
/* Historically the command parser in virsh allowed many optional arguments
* which were documented as non-positional to be filled positionally. To
* preserve this functionality those need to be annotated with the
* 'unwanted_positional' flag. New options must not use this flag */
bool unwanted_positional;
unsigned int flags; /* flags */
const char *help; /* non-NULL help string; or for VSH_OT_ALIAS
* the name of a later public option */