[pve-devel] applied: [pve-common] PVE::CLIFormatter::print_api_result - use print_api_list to print arrays

Thomas Lamprecht t.lamprecht at proxmox.com
Thu Jul 5 18:38:34 CEST 2018


On 7/5/18 9:26 AM, Dietmar Maurer wrote:
> Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
> ---
>  src/PVE/CLIFormatter.pm | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/src/PVE/CLIFormatter.pm b/src/PVE/CLIFormatter.pm
> index 052ed6d..08907fb 100644
> --- a/src/PVE/CLIFormatter.pm
> +++ b/src/PVE/CLIFormatter.pm
> @@ -384,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");
> 

applied




More information about the pve-devel mailing list