]> git.proxmox.com Git - pve-client.git/blobdiff - pveclient
add missing file PVE/APIClient/Commands/config.pm
[pve-client.git] / pveclient
index 6a06a88181b4340684591be712e74fbfec3664bc..f18dab902c231510aa8de7d2f76efa36007b9eef 100755 (executable)
--- a/pveclient
+++ b/pveclient
@@ -12,6 +12,7 @@ use PVE::CLIHandler;
 
 use PVE::APIClient::LWP;
 use PVE::APIClient::Helpers;
+use PVE::APIClient::Commands::config;
 use PVE::APIClient::Commands::remote;
 use PVE::APIClient::Commands::list;
 use PVE::APIClient::Commands::lxc;
@@ -31,10 +32,12 @@ sub call_method {
     die "implement me";
 }
 
+
 my $cli_class_handlers = {
     list => 'PVE::APIClient::Commands::list',
     lxc => 'PVE::APIClient::Commands::lxc',
     remote => 'PVE::APIClient::Commands::remote',
+    config => 'PVE::APIClient::Commands::config',
     help => 'PVE::APIClient::Commands::help',
 };
 
@@ -44,20 +47,20 @@ if (!defined($cmd)) {
     exit(-1);
 }
 
-if ($cmd eq 'get') {
-    my $method = 'GET';
+my $method_map = {
+    create => 'POST',
+    set => 'PUT',
+    get => 'GET',
+    delete => 'DELETE',
+};
+
+if (my $method = $method_map->{$cmd}) {
     my $path;
     if (scalar(@ARGV) && $ARGV[0] !~ m/^\-/)  {
        $path = shift @ARGV;
     }
     my $res = call_method($path, $method, \@ARGV);
     die "implement me";
-} elsif ($cmd eq 'set') {
-    die "implement me";
-} elsif ($cmd eq 'create') {
-    die "implement me";
-} elsif ($cmd eq 'delete') {
-    die "implement me";
 } elsif (my $class = $cli_class_handlers->{$cmd}) {
     $class->run_cli_handler();
 } elsif ($cmd eq 'bashcomplete') {
@@ -68,25 +71,43 @@ if ($cmd eq 'get') {
     if ($ENV{COMP_LINE} =~ m/^(.*pveclient\s+($cmdlist)\s+)(.*)$/) {
        my $cmd = $2;
        my $class = $cli_class_handlers->{$cmd} || die "internal error";
-       $ENV{COMP_LINE} = "pveclient $3";
-       $ENV{COMP_POINT} = length($ENV{COMP_LINE});
-       @ARGV = ('bashcomplete', 'pveclient', $ARGV[1], $ARGV[2]);
 
+       if ($cmd eq 'list') { # simple commands
+           $ENV{COMP_LINE} = "pveclient $3";
+           $ENV{COMP_POINT} = length($ENV{COMP_LINE});
+           @ARGV = ('bashcomplete', 'pveclient', $ARGV[1], $ARGV[2]);
+       } else {
+           $ENV{COMP_LINE} = "pveclient $3";
+           $ENV{COMP_POINT} = length($ENV{COMP_LINE});
+           @ARGV = ('bashcomplete', 'pveclient', $ARGV[1], $ARGV[2]);
+       }
        $class->run_cli_handler();
 
     } else {
 
        my $cmdline = substr($ENV{COMP_LINE}, 0, $ENV{COMP_POINT});
        my ($bash_command, $cur, $prev) = @ARGV;
-       $cmdline =~ s/$cur$//;
+       $cmdline =~ s/\Q$cur\E$//;
 
        my $args = PVE::Tools::split_args($cmdline);
 
-       my @cmds = ('get', 'set', 'create', 'delete', keys %$cli_class_handlers);
+       my @cmds = (keys %$method_map, keys %$cli_class_handlers);
        if (scalar(@$args) == 1) {
            foreach my $p (@cmds) {
                print "$p\n" if $p =~ m/^$cur/;
            }
+       } elsif (scalar(@$args) == 2) {
+           if (my $method = $method_map->{$args->[1]}) {
+               PVE::APIClient::Helpers::complete_api_path($cur);
+           }
+       } elsif (scalar(@$args) >= 3) {
+           my $path = $args->[2];
+           if (my $method = $method_map->{$args->[1]}) {
+               if (my $info = PVE::APIClient::Helpers::lookup_api_method($path, $method, 1)) {
+                   my $prop = $info->{parameters}->{properties};
+                   PVE::APIClient::Helpers::complete_api_call_options($method, $prop, $prev, $cur, $args);
+               }
+           }
        }
     }