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

Dietmar Maurer dietmar at proxmox.com
Wed Jun 27 12:52:29 CEST 2018


In order to draw the new asciiart border ...

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

diff --git a/src/PVE/CLIHandler.pm b/src/PVE/CLIHandler.pm
index 6cb51b5..1d68708 100644
--- a/src/PVE/CLIHandler.pm
+++ b/src/PVE/CLIHandler.pm
@@ -568,9 +568,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