+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;
+}
+
+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) = @_;
+
+ foreach my $pname (keys %$properties) {
+ if (my $d = $properties->{$pname}) {
+ if (defined(my $format = $d->{format})) {
+ if (ref($format)) {
+ $__real_remove_formats->($format);
+ } elsif (!PVE::APIClient::JSONSchema::get_format($format)) {
+ # simply remove unknown format definitions
+ delete $d->{format};
+ }
+ }
+ }
+ }
+};
+
+my $remove_unknown_formats; $remove_unknown_formats = sub {