This restores the behavior for sort_key as it's described in the comment for print_text_table.
Fixes warnings, e.g. pvesh get /nodes/<NODE>/network would print "use of uninitialized"-warnings if there are inactive network interfaces, because for those, 'active' is undef. Signed-off-by: Fabian Ebner <f.eb...@proxmox.com> --- src/PVE/CLIFormatter.pm | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/PVE/CLIFormatter.pm b/src/PVE/CLIFormatter.pm index 0e9cbe6..9f141e1 100644 --- a/src/PVE/CLIFormatter.pm +++ b/src/PVE/CLIFormatter.pm @@ -144,6 +144,23 @@ sub data_to_text { } } +sub leftmost_sortable_property { + my ($data, $properties) = @_; + + foreach my $property (@{$properties}) { + my $sortable = 1; + foreach my $entry (@{$data}) { + if (!defined($entry->{$property})) { + $sortable = 0; + last; + } + } + return $property if $sortable eq 1; + } + + return undef; +} + # prints a formatted table with a title row. # $data - the data to print (array of objects) # $returnprops -json schema property description @@ -170,7 +187,7 @@ sub print_text_table { my $utf8 = $terminal_opts->{utf8}; my $encoding = $terminal_opts->{encoding} // 'UTF-8'; - $sort_key //= $props_to_print->[0]; + $sort_key //= leftmost_sortable_property($data, $props_to_print); if (defined($sort_key) && $sort_key ne 0) { my $type = $returnprops->{$sort_key}->{type} // 'string'; -- 2.20.1 _______________________________________________ pve-devel mailing list pve-devel@pve.proxmox.com https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel