]> git.proxmox.com Git - pve-common.git/commitdiff
cli: refactor and use $cmddef directly
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 18 Dec 2017 09:21:35 +0000 (10:21 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 29 Dec 2017 10:51:20 +0000 (11:51 +0100)
passing one param less to the helper methods

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Reviewed-by: Dominik Csapak <d.csapak@proxmox.com>
Acked-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/PVE/CLIHandler.pm

index efc8a1a2bb4ffe67e0a94ac75504378ce0ba2611..c6f11f6d449da44cb37a5e738427e9e7c5323e26 100644 (file)
@@ -198,7 +198,7 @@ sub print_usage_short {
 }
 
 my $print_bash_completion = sub {
 }
 
 my $print_bash_completion = sub {
-    my ($cmddef, $simple_cmd, $bash_command, $cur, $prev) = @_;
+    my ($simple_cmd, $bash_command, $cur, $prev) = @_;
 
     my $debug = 0;
 
 
     my $debug = 0;
 
@@ -351,12 +351,11 @@ sub generate_asciidoc_synopsis {
 
     no strict 'refs';
     my $def = ${"${class}::cmddef"};
 
     no strict 'refs';
     my $def = ${"${class}::cmddef"};
+    $cmddef = $def;
 
     if (ref($def) eq 'ARRAY') {
        print_simple_asciidoc_synopsis(@$def);
     } else {
 
     if (ref($def) eq 'ARRAY') {
        print_simple_asciidoc_synopsis(@$def);
     } else {
-       $cmddef = $def;
-
        $cmddef->{help} = [ __PACKAGE__, 'help', ['cmd'] ];
 
        print_asciidoc_synopsis();
        $cmddef->{help} = [ __PACKAGE__, 'help', ['cmd'] ];
 
        print_asciidoc_synopsis();
@@ -371,16 +370,14 @@ sub setup_environment {
 }
 
 my $handle_cmd  = sub {
 }
 
 my $handle_cmd  = sub {
-    my ($def, $cmdname, $cmd, $args, $pwcallback, $preparefunc, $stringfilemap) = @_;
-
-    $cmddef = $def;
-    $exename = $cmdname;
+    my ($args, $pwcallback, $preparefunc, $stringfilemap) = @_;
 
     $cmddef->{help} = [ __PACKAGE__, 'help', ['cmd'] ];
 
     # call verifyapi before setup_environment(), because we do not want to
     # execute any real code in this case
 
 
     $cmddef->{help} = [ __PACKAGE__, 'help', ['cmd'] ];
 
     # call verifyapi before setup_environment(), because we do not want to
     # execute any real code in this case
 
+    my $cmd = shift @$args;
     if (!$cmd) {
        print_usage_short (\*STDERR, "no command specified");
        exit (-1);
     if (!$cmd) {
        print_usage_short (\*STDERR, "no command specified");
        exit (-1);
@@ -392,7 +389,7 @@ my $handle_cmd  = sub {
     $cli_handler_class->setup_environment();
 
     if ($cmd eq 'bashcomplete') {
     $cli_handler_class->setup_environment();
 
     if ($cmd eq 'bashcomplete') {
-       &$print_bash_completion($cmddef, 0, @$args);
+       &$print_bash_completion(undef, @$args);
        return;
     }
 
        return;
     }
 
@@ -414,9 +411,9 @@ my $handle_cmd  = sub {
 };
 
 my $handle_simple_cmd = sub {
 };
 
 my $handle_simple_cmd = sub {
-    my ($def, $args, $pwcallback, $preparefunc, $stringfilemap) = @_;
+    my ($args, $pwcallback, $preparefunc, $stringfilemap) = @_;
 
 
-    my ($class, $name, $arg_param, $uri_param, $outsub) = @{$def};
+    my ($class, $name, $arg_param, $uri_param, $outsub) = @{$cmddef};
     die "no class specified" if !$class;
 
     if (scalar(@$args) >= 1) {
     die "no class specified" if !$class;
 
     if (scalar(@$args) >= 1) {
@@ -436,7 +433,7 @@ my $handle_simple_cmd = sub {
     if (scalar(@$args) >= 1) {
        if ($args->[0] eq 'bashcomplete') {
            shift @$args;
     if (scalar(@$args) >= 1) {
        if ($args->[0] eq 'bashcomplete') {
            shift @$args;
-           &$print_bash_completion({ $name => $def }, $name, @$args);
+           &$print_bash_completion($name, @$args);
            return;
        }
     }
            return;
        }
     }
@@ -472,14 +469,12 @@ sub run_cli_handler {
     initlog($exename);
 
     no strict 'refs';
     initlog($exename);
 
     no strict 'refs';
-    my $def = ${"${class}::cmddef"};
+    $cmddef = ${"${class}::cmddef"};
 
 
-    if (ref($def) eq 'ARRAY') {
-       &$handle_simple_cmd($def, \@ARGV, $pwcallback, $preparefunc, $stringfilemap);
+    if (ref($cmddef) eq 'ARRAY') {
+       &$handle_simple_cmd(\@ARGV, $pwcallback, $preparefunc, $stringfilemap);
     } else {
     } else {
-       $cmddef = $def;
-       my $cmd = shift @ARGV;
-       &$handle_cmd($cmddef, $exename, $cmd, \@ARGV, $pwcallback, $preparefunc, $stringfilemap);
+       &$handle_cmd(\@ARGV, $pwcallback, $preparefunc, $stringfilemap);
     }
 
     exit 0;
     }
 
     exit 0;