generate_usage_str: do no generate help for unknown commands
authorDietmar Maurer <dietmar@proxmox.com>
Wed, 13 Jun 2018 06:00:22 +0000 (08:00 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 13 Jun 2018 06:16:45 +0000 (08:16 +0200)
Before:

...
USAGE: pvesm aaa zfsscan

With this patch applied:

no such command 'aaa'

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
src/PVE/CLIHandler.pm

index 316d29d..5cdffa3 100644 (file)
@@ -93,8 +93,8 @@ sub resolve_cmd {
                $cmd = $argv->[$i]; 
            }
            $cmdstr .= " $cmd";
-           last if !defined($def->{$cmd});
            $def = $def->{$cmd};
+           last if !defined($def);
 
            if (ref($def) eq 'ARRAY') {
                # could expand to a real command, rest of $argv are its arguments
@@ -132,6 +132,7 @@ sub generate_usage_str {
        $cli_handler_class->can('string_param_file_mapping');
 
     my ($subcmd, $def, undef, undef, $cmdstr) = resolve_cmd($cmd);
+    die "no such command '$cmd->[0]'\n" if !defined($def) && ref($cmd) eq 'ARRAY';
 
     my $generate;
     $generate = sub {