Missed something (comment inline)
On 12/05/2017 08:56 AM, Dominik Csapak wrote:
Reviewed-by: Dominik Csapak <d.csa...@proxmox.com>

On 11/06/2017 02:54 PM, Thomas Lamprecht wrote:
use shorter and also a bit faster methods to expand and get comand
names
---
  src/PVE/CLIHandler.pm | 25 +++----------------------
  1 file changed, 3 insertions(+), 22 deletions(-)

diff --git a/src/PVE/CLIHandler.pm b/src/PVE/CLIHandler.pm
index c787ac4..ab1440c 100644
--- a/src/PVE/CLIHandler.pm
+++ b/src/PVE/CLIHandler.pm
@@ -24,33 +24,14 @@ my $expand_command_name = sub {
      my ($def, $cmd) = @_;
      if (!$def->{$cmd}) {
-    my $expanded;
-    for my $k (keys(%$def)) {
-        if ($k =~ m/^$cmd/) {
-        if ($expanded) {
-            $expanded = undef; # more than one match
-            last;
-        } else {
-            $expanded = $k;
-        }
-        }
-    }
-    $cmd = $expanded if $expanded;
+    my @expanded = grep { /^$cmd/ } keys %$def;

we should not directly give the $cmd variable to aregex but do something like:

/^\Q$cmd\E/

else a command like this matches:

pveum rolead+

(or is this something we want?)

+    return $expanded[0] if scalar(@expanded) == 1; # enforce exact match
      }
      return $cmd;
  };
  my $complete_command_names = sub {
-    my $res = [];
-
-    return if ref($cmddef) ne 'HASH';
-
-    foreach my $cmd (keys %$cmddef) {
-    next if $cmd eq 'help';
-    push @$res, $cmd;
-    }
-
-    return $res;
+    return [ sort keys %$cmddef ];
  };
  __PACKAGE__->register_method ({



_______________________________________________
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


_______________________________________________
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to