]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/CLIHandler.pm
allow fall back to default completion
[pve-common.git] / src / PVE / CLIHandler.pm
index b32c2886e9fc9964da777680d21009790836cab6..149353797238ef481e135fafb9e65b51259a21bf 100644 (file)
@@ -113,7 +113,8 @@ __PACKAGE__->register_method ({
 sub print_simple_pod_manpage {
     my ($podfn, $class, $name, $arg_param, $uri_param) = @_;
 
-    die "not initialized" if !($cmddef && $exename && $cli_handler_class);
+    die "not initialized" if !$cli_handler_class;
+
     my $pwcallback = $cli_handler_class->can('read_password');
 
     my $synopsis = " $name help\n\n";
@@ -336,7 +337,7 @@ sub generate_bash_completions {
 # this modifies global var, but I found no better way
 COMP_WORDBREAKS=\${COMP_WORDBREAKS//:}
 
-complete -C '$exename bashcomplete' $exename
+complete -o default -C '$exename bashcomplete' $exename
 __EOD__
 }
 
@@ -468,7 +469,7 @@ sub run_cli {
     
     die "password callback is no longer supported" if $pwcallback;
 
-    run_cli_handler($class, podfn => $podfn, preparefunc => $preparefunc);
+    run_cli_handler($class, podfn => $podfn, prepare => $preparefunc);
 }
 
 sub run_cli_handler {
@@ -478,8 +479,16 @@ sub run_cli_handler {
 
     $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
 
+    foreach my $key (keys %params) {
+       next if $key eq 'podfn';
+       next if $key eq 'prepare';
+       next if $key eq 'no_init'; # used by lxc hooks
+       die "unknown parameter '$key'";
+    }
+
     my $podfn = $params{podfn};
-    my $preparefunc = $params{preparefunc};
+    my $preparefunc = $params{prepare};
+    my $no_init = $params{no_init};
 
     my $pwcallback = $class->can('read_password');
 
@@ -490,10 +499,10 @@ sub run_cli_handler {
     if ($class !~ m/^PVE::Service::/) {
        die "please run as root\n" if $> != 0;
 
-       PVE::INotify::inotify_init();
+       PVE::INotify::inotify_init() if !$no_init;
 
        my $rpcenv = PVE::RPCEnvironment->init('cli');
-       $rpcenv->init_request();
+       $rpcenv->init_request() if !$no_init;
        $rpcenv->set_language($ENV{LANG});
        $rpcenv->set_user('root@pam');
     }