]> git.proxmox.com Git - pve-common.git/commitdiff
cli handler: fix "return" statement followed by "sort" critic
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 11 Apr 2023 13:08:29 +0000 (15:08 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 11 Apr 2023 13:08:54 +0000 (15:08 +0200)
As that's undefined behavior if the containing sub is called in
scalar context.

https://metacpan.org/pod/Perl::Critic::Policy::Subroutines::ProhibitReturnSort

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PVE/CLIHandler.pm

index 64c3f95d120a5d97e9ff24b620098b360323df09..64de8f783d552d0a12a000cffb462b8402492e9a 100644 (file)
@@ -350,7 +350,7 @@ sub print_usage_short {
 
     print {$fd} generate_usage_str('short', $cmd, ' ' x 7, $cmd ? '' : "\n", sub {
        my ($h) = @_;
-       return sort {
+       my @sorted_commands = sort {
            if (ref($h->{$a}) eq 'ARRAY' && ref($h->{$b}) eq 'ARRAY') {
                # $a and $b are both real commands order them by their class
                return $h->{$a}->[0] cmp $h->{$b}->[0] || $a cmp $b;
@@ -362,6 +362,7 @@ sub print_usage_short {
                return $a cmp $b;
            }
        } keys %$h;
+       return @sorted_commands;
     });
 }