]> git.proxmox.com Git - pve-client.git/blobdiff - pveclient
add split_args helper
[pve-client.git] / pveclient
index 30d86681805a2e49357eca32460a06e48bd935df..d8d4d15da682bc772558e0099d75761dd46b6d12 100755 (executable)
--- a/pveclient
+++ b/pveclient
@@ -3,6 +3,7 @@
 use strict;
 use warnings;
 use lib '/usr/share/pve-client';
+use lib '.';
 use Data::Dumper;
 
 use PVE::JSONSchema;
@@ -11,13 +12,22 @@ use PVE::CLIHandler;
 use PVE::APIClient::LWP;
 use PVE::APIClient::Helpers;
 use PVE::APIClient::Commands::remote;
+use PVE::APIClient::Commands::lxc;
 
 use JSON;
 
 sub print_usage {
 
-    die "Usage: implement me";
-    exit(-1);
+    my $text = "pveclient usage:\n\n";
+
+    $text .= "pveclient remote <help|add|remove> {options}\n\n";
+
+    $text .= "pveclient lxc <help|create|destroy|...> {options}\n\n";
+
+    $text .= "pveclient <get/set/create/delete> <path> {options}\n\n";
+
+    print STDERR $text;
+
 }
 
 sub call_method {
@@ -50,7 +60,7 @@ sub call_method {
 #my $res = $conn->get("/", {});
 #print to_json($res, { pretty => 1, canonical => 1});
 
-my $cmd = shift || print_usage();
+my $cmd = shift || (print_usage() && exit(-1));
 
 if ($cmd eq 'get') {
     my $method = 'GET';
@@ -66,8 +76,25 @@ if ($cmd eq 'get') {
     die "implement me";
 } elsif ($cmd eq 'delete') {
     die "implement me";
+} elsif ($cmd eq 'lxc') {
+    PVE::APIClient::Commands::lxc->run_cli_handler();
 } elsif ($cmd eq 'remote') {
     PVE::APIClient::Commands::remote->run_cli_handler();
+} elsif ($cmd eq 'bashcomplete') {
+
+    my $cmdline = substr($ENV{COMP_LINE}, 0, $ENV{COMP_POINT});
+    $cmdline =~ s/$cur$//;
+
+    my ($bash_command, $cur, $prev) = @ARGV;
+
+    my $args = [split(/\s+/, $cmdline)];
+
+    if (scalar(@$args) == 1) {
+       foreach my $p (qw(get set create delete lxc remote)) {
+           print "$p\n" if $p =~ m/^$cur/;
+       }
+    }
+
 } else {
     print_usage();
 }