X-Git-Url: https://git.proxmox.com/?p=pve-client.git;a=blobdiff_plain;f=PVE%2FAPIClient%2FHelpers.pm;h=7e4447dd8ab6c9b3a070ec4cedf810dd7bb97e21;hp=9ad060324135e25e4d07b8c2f14f165df48f5891;hb=a00bef992d68c429798d031ecd6dec7935cb381b;hpb=936c07ece1ca26ffd5b762191cd0a97e3fd8815e diff --git a/PVE/APIClient/Helpers.pm b/PVE/APIClient/Helpers.pm index 9ad0603..7e4447d 100644 --- a/PVE/APIClient/Helpers.pm +++ b/PVE/APIClient/Helpers.pm @@ -20,30 +20,13 @@ my $pve_api_definition; my $pve_api_definition_fn = "/usr/share/pve-client/pve-api-definition.dat"; -my $method_map = { +our $method_map = { create => 'POST', set => 'PUT', get => 'GET', delete => 'DELETE', }; -my $default_output_format = 'text'; -my $client_output_format = $default_output_format; - -sub set_output_format { - my ($format) = @_; - - if (!defined($format)) { - $client_output_format = $default_output_format; - } else { - $client_output_format = $format; - } -} - -sub get_output_format { - return $client_output_format; -} - my $__real_remove_formats; $__real_remove_formats = sub { my ($properties) = @_; @@ -220,21 +203,20 @@ sub complete_api_path { if (my $children = $info->{children}) { foreach my $c (@$children) { my $ctext = $c->{text}; + push @$res, "${prefix}$ctext" if $ctext =~ m/^\Q$rest/; if ($ctext =~ m/^\{(\S+)\}$/) { - push @$res, "$prefix$ctext"; - push @$res, "$prefix$ctext/"; - if (length($rest)) { + if (length($rest) && $rest ne $ctext) { push @$res, "$prefix$rest"; - push @$res, "$prefix$rest/"; } - } elsif ($ctext =~ m/^\Q$rest/) { - push @$res, "$prefix$ctext"; - push @$res, "$prefix$ctext/" if $c->{children}; } } } } + if (scalar(@$res) == 1) { + $res = [$res->[0], "$res->[0]/"]; + } + return $res; } @@ -405,23 +387,12 @@ sub extract_even_elements { return [ grep { ($ind++ % 2) == 0 } @$list ]; } -sub print_result { - my ($data, $result_schema, $param_order) = @_; - - my $options = {}; - PVE::APIClient::CLIFormatter::query_terminal_options($options); - - my $format = get_output_format(); - PVE::APIClient::CLIFormatter::print_api_result( - $format, $data, $result_schema, $param_order, $options); -} - sub print_ordered_result { - my ($property_list, $data, $result_schema) = @_; + my ($property_list, $data, $result_schema, $options) = @_; my $param_order = extract_even_elements($property_list); - print_result($data, $result_schema, $param_order); + PVE::APIClient::CLIFormatter::print_api_result($data, $result_schema, $param_order, $options); } 1;