]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/CLIFormatter.pm
PVE::CLIFormatter::print_api_result - use print_api_list to print arrays
[pve-common.git] / src / PVE / CLIFormatter.pm
index 549ed3177964ea7d7950cc0acaed7ff1058e2875..08907fb5077229aee20d4f05483d5f196f7f4def 100644 (file)
@@ -20,6 +20,15 @@ sub render_timestamp {
 
 PVE::JSONSchema::register_renderer('timestamp', \&render_timestamp);
 
+sub render_timestamp_gmt {
+    my ($epoch) = @_;
+
+    # ISO 8601 date format, standard Greenwich time zone
+    return strftime("%F %H:%M:%S", gmtime($epoch));
+}
+
+PVE::JSONSchema::register_renderer('timestamp_gmt', \&render_timestamp_gmt);
+
 sub render_duration {
     my ($duration_in_seconds) = @_;
 
@@ -375,14 +384,17 @@ sub print_api_result {
            print_api_list($kvstore, $schema, ['key', 'value'], $options);
        } elsif ($type eq 'array') {
            return if !scalar(@$data);
+           $options->{border} = $format eq 'text';
            my $item_type = $result_schema->{items}->{type};
            if ($item_type eq 'object') {
-               $options->{border} = $format eq 'text';
                print_api_list($data, $result_schema, $props_to_print, $options);
            } else {
-               foreach my $entry (@$data) {
-                   print encode($encoding, data_to_text($entry, $result_schema->{items}, $options) . "\n");
+               my $kvstore = [];
+               foreach my $value (@$data) {
+                   push @$kvstore, { value => $value };
                }
+               my $schema = { type => 'array', items => { type => 'object', properties => { value => $result_schema->{items} }}};
+               print_api_list($kvstore, $schema, ['value'], $options);
            }
        } else {
            print encode($encoding, "$data\n");