[pmg-devel] [PATCH v3 common] get_options: don't set optional positional params to `undef`
Wolfgang Bumiller
w.bumiller at proxmox.com
Tue Mar 16 11:24:24 CET 2021
Currently this happened if (and only if) at least one
positional parameter was passed.
We run into this with
`pmgconfig cert delete <type> [<restart>]`
vs
`pvenode cert delete [<restart>]`
where in the PVE case the `restart` option was simply
omitted, whereas for PMG due to the existence of `<type>`
the `restart` option was explicitly passedset in the $opts
hash but ended up being `undef`.
Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
---
* New in this version
src/PVE/JSONSchema.pm | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm
index 20d72b3..4864549 100644
--- a/src/PVE/JSONSchema.pm
+++ b/src/PVE/JSONSchema.pm
@@ -1640,11 +1640,15 @@ sub get_options {
if (!@$args) {
# check if all left-over arg_param are optional, else we
# must die as the mapping is then ambigious
- for (my $j = $i; $j < scalar(@$arg_param); $j++) {
- my $prop = $arg_param->[$j];
+ for (; $i < scalar(@$arg_param); $i++) {
+ my $prop = $arg_param->[$i];
raise("not enough arguments\n", code => HTTP_BAD_REQUEST)
if !$schema->{properties}->{$prop}->{optional};
}
+ if ($arg_param->[-1] eq 'extra-args') {
+ $opts->{'extra-args'} = [];
+ }
+ last;
}
$opts->{$arg_name} = shift @$args;
}
--
2.20.1
More information about the pmg-devel
mailing list