From: Thomas Lamprecht Date: Wed, 27 Jun 2018 09:28:36 +0000 (+0200) Subject: cli: print_text_table: followup code cleanup X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=commitdiff_plain;h=8379465981dd06ae359943692c6656e74700392b;hp=9ac6416ec828cc32c653950ed7813fbb623df974 cli: print_text_table: followup code cleanup Signed-off-by: Thomas Lamprecht --- diff --git a/src/PVE/CLIHandler.pm b/src/PVE/CLIHandler.pm index 9cf7988..b939a22 100644 --- a/src/PVE/CLIHandler.pm +++ b/src/PVE/CLIHandler.pm @@ -480,7 +480,7 @@ sub print_text_table { $longest = $len if $len > $longest; $sortable = 0 if !defined($entry->{$prop}); } - $cutoff = (defined($cutoff) && $cutoff < $longest) ? $cutoff : $longest; + $cutoff = $longest if !defined($cutoff) || $cutoff > $longest; $sort_key //= $prop if $sortable; $colopts->{$prop} = { @@ -489,14 +489,15 @@ sub print_text_table { cutoff => $cutoff, }; + # skip alignment and cutoff on last column $formatstring .= ($i == ($column_count - 1)) ? "%s\n" : "%-${cutoff}s "; } printf $formatstring, map { $colopts->{$_}->{title} } @$props_to_print; if (defined($sort_key)) { - if ($returnprops->{$sort_key}->{type} eq 'integer' || - $returnprops->{$sort_key}->{type} eq 'number') { + my $type = $returnprops->{$sort_key}->{type}; + if ($type eq 'integer' || $type eq 'number') { @$data = sort { $a->{$sort_key} <=> $b->{$sort_key} } @$data; } else { @$data = sort { $a->{$sort_key} cmp $b->{$sort_key} } @$data;