use PVE::APIClient::JSONSchema;
use PVE::APIClient::Exception qw(raise);
+use PVE::APIClient::CLIFormatter;
+use PVE::APIClient::CLIHandler;
+use PVE::APIClient::PTY;
use Encode::Locale;
use Encode;
use HTTP::Status qw(:constants);
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',
return $client_output_format;
}
-sub print_result {
- my ($data, $result_schema) = @_;
-
- my $format = get_output_format();
-
- return if $result_schema->{type} eq 'null';
-
- # TODO: implement different output formats ($format)
-
- if ($format eq 'json') {
- print to_json($data, {utf8 => 1, allow_nonref => 1, canonical => 1, pretty => 1 });
- } elsif ($format eq 'text') {
- my $type = $result_schema->{type};
- if ($type eq 'object') {
- die "implement me";
- } elsif ($type eq 'array') {
- my $item_type = $result_schema->{items}->{type};
- if ($item_type eq 'object') {
- die "implement me";
- } elsif ($item_type eq 'array') {
- die "implement me";
- } else {
- foreach my $el (@$data) {
- print "$el\n"
- }
- }
- } else {
- print "$data\n";
- }
- } else {
- die "internal error: unknown output format"; # should not happen
- }
-}
-
-
my $__real_remove_formats; $__real_remove_formats = sub {
my ($properties) = @_;
my $stack = [ grep { length($_) > 0 } split('\/+' , $path)]; # skip empty fragments
- my $child = $map_path_to_info->(get_api_definition(), $stack, $uri_param);
+ my $api = get_api_definition();
+
+ my $child = scalar(@$stack) ? $map_path_to_info->($api->{children}, $stack, $uri_param) : $api;
if (!($child && $child->{info} && $child->{info}->{$method})) {
return undef if $noerr;
sub complete_api_path {
my ($text) = @_;
- get_api_definition(); # make sure API data is loaded
+ my $api = get_api_definition(); # make sure API data is loaded
$text =~ s!^/!!;
my $info;
if (!defined($dir)) {
$dir = '';
- $info = { children => $pve_api_definition };
+ $info = $api;
} else {
my $stack = [ grep { length($_) > 0 } split('\/+' , $dir)]; # skip empty fragments
- $info = $map_path_to_info->($pve_api_definition, $stack, {});
+ $info = $map_path_to_info->($api->{children}, $stack, {});
}
my $res = [];
die $@ if $@;
}
+sub extract_even_elements {
+ my ($list) = @_;
+
+ my $ind = 0;
+ 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 $param_order = extract_even_elements($property_list);
+
+ print_result($data, $result_schema, $param_order);
+}
1;