X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=blobdiff_plain;f=src%2FPVE%2FJSONSchema.pm;h=f0ac44139883234d4b003e26257f0f89a35a5fb6;hp=0e722b81b0812c104a80eef3e526dec746884baa;hb=b521204225fbabdb41ac9d63a392942e258dd9f5;hpb=c7171ff272c9070958c8db1135b9305d6197f307 diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm index 0e722b8..f0ac441 100644 --- a/src/PVE/JSONSchema.pm +++ b/src/PVE/JSONSchema.pm @@ -121,6 +121,22 @@ sub get_format { return $format_list->{$format}; } +my $renderer_hash = {}; + +sub register_renderer { + my ($name, $code) = @_; + + die "renderer '$name' already registered\n" + if $renderer_hash->{$name}; + + $renderer_hash->{$name} = $code; +} + +sub get_renderer { + my ($name) = @_; + return $renderer_hash->{$name}; +} + # register some common type for pve register_format('string', sub {}); # allow format => 'string-list' @@ -1139,6 +1155,11 @@ my $default_schema_noref = { }, }, }, + print_width => { + type => "integer", + description => "For CLI context, this defines the maximal width to print before truncating", + optional => 1, + }, } }; @@ -1333,7 +1354,7 @@ sub method_get_child_link { # a way to parse command line parameters, using a # schema to configure Getopt::Long sub get_options { - my ($schema, $args, $arg_param, $fixed_param, $pwcallback, $param_mapping_hash) = @_; + my ($schema, $args, $arg_param, $fixed_param, $param_mapping_hash) = @_; if (!$schema || !$schema->{properties}) { raise("too many arguments\n", code => HTTP_BAD_REQUEST) @@ -1362,11 +1383,6 @@ sub get_options { # optional and call the mapping function afterwards. push @getopt, "$prop:s"; push @interactive, [$prop, $mapping->{func}]; - } elsif ($prop eq 'password' && $pwcallback) { - # we do not accept plain password on input line, instead - # we turn this into a boolean option and ask for password below - # using $pwcallback() (for security reasons). - push @getopt, "$prop"; } elsif ($pd->{type} eq 'boolean') { push @getopt, "$prop:s"; } else { @@ -1406,12 +1422,14 @@ sub get_options { raise("too many arguments\n", code => HTTP_BAD_REQUEST) if scalar(@$args) != 0; } - } - - if (my $pd = $schema->{properties}->{password}) { - if ($pd->{type} ne 'boolean' && $pwcallback) { - if ($opts->{password} || !$pd->{optional}) { - $opts->{password} = &$pwcallback(); + } else { + if (ref($arg_param)) { + foreach my $arg_name (@$arg_param) { + if ($arg_name eq 'extra-args') { + $opts->{'extra-args'} = []; + } else { + raise("not enough arguments\n", code => HTTP_BAD_REQUEST); + } } } }