[pve-devel] [PATCH pve-common] generate_usage_str: do no generate help for unknown commands

Dietmar Maurer dietmar at proxmox.com
Wed Jun 13 08:00:22 CEST 2018


Before:

...
USAGE: pvesm aaa zfsscan

With this patch applied:

no such command 'aaa'

Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
 src/PVE/CLIHandler.pm | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/PVE/CLIHandler.pm b/src/PVE/CLIHandler.pm
index 316d29d..5cdffa3 100644
--- a/src/PVE/CLIHandler.pm
+++ b/src/PVE/CLIHandler.pm
@@ -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 {
-- 
2.11.0




More information about the pve-devel mailing list