X-Git-Url: https://git.proxmox.com/?p=pve-client.git;a=blobdiff_plain;f=PVE%2FAPIClient%2FHelpers.pm;h=3429f4db21e6f736eab4515555fa91d4a6fe11b7;hp=9d599d6cd27b0b3f83d0ca688468aa9e8733f430;hb=4aba8d31fe4441125c4af295e67534797bb27bfb;hpb=55d17e7e1afc13816e8cd92f928fc65ba60e6820 diff --git a/PVE/APIClient/Helpers.pm b/PVE/APIClient/Helpers.pm index 9d599d6..3429f4d 100644 --- a/PVE/APIClient/Helpers.pm +++ b/PVE/APIClient/Helpers.pm @@ -27,23 +27,6 @@ our $method_map = { 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,13 @@ 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::query_terminal_options($options); + PVE::APIClient::CLIFormatter::print_api_result($data, $result_schema, $param_order, $options); } 1;