[pve-devel] [pve-common 2/7] cli: print_api_result: use print_api_list to print objects

Dietmar Maurer dietmar at proxmox.com
Thu Jun 28 13:03:56 CEST 2018


In order to draw the new asciiart border ...

Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
 src/PVE/CLIFormatter.pm | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/PVE/CLIFormatter.pm b/src/PVE/CLIFormatter.pm
index b55861a..80504b2 100644
--- a/src/PVE/CLIFormatter.pm
+++ b/src/PVE/CLIFormatter.pm
@@ -143,9 +143,12 @@ sub print_api_result {
 	my $type = $result_schema->{type};
 	if ($type eq 'object') {
 	    $props_to_print = [ sort keys %$data ] if !defined($props_to_print);
+	    my $kvstore = [];
 	    foreach my $key (@$props_to_print) {
-		print $key . ": " .  data_to_text($data->{$key}) . "\n";
+		push @$kvstore, { key => $key, value => data_to_text($data->{$key}) };
 	    }
+	    my $schema = { type => 'array', items => { type => 'object' }};
+	    print_api_list($kvstore, $schema, ['key', 'value'], 0, $format eq 'text');
 	} elsif ($type eq 'array') {
 	    return if !scalar(@$data);
 	    my $item_type = $result_schema->{items}->{type};
-- 
2.11.0



More information about the pve-devel mailing list