X-Git-Url: https://git.proxmox.com/?p=pve-client.git;a=blobdiff_plain;f=pveclient;h=091af96bb160a2ee7ab79a3e029794984770a9d0;hp=8ea109d042ed7683a59681f85babad86f34a2e7d;hb=a8aa5b63711a9b0ee8536aac91901b1b38609c09;hpb=565bbc73ca66a8a0612df1c04e8f5b4a07f02ae1 diff --git a/pveclient b/pveclient index 8ea109d..091af96 100755 --- a/pveclient +++ b/pveclient @@ -3,20 +3,31 @@ use strict; use warnings; use lib '/usr/share/pve-client'; +use lib '.'; use Data::Dumper; +use PVE::JSONSchema; 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 {options}\n\n"; + + $text .= "pveclient lxc {options}\n\n"; + + $text .= "pveclient {options}\n\n"; + + print STDERR $text; + } sub call_method { @@ -25,7 +36,7 @@ sub call_method { die "missing API path\n" if !defined($path); my $info = PVE::APIClient::Helpers::lookup_api_method($path, $method); - my $param = PVE::APIClient::Helpers::get_options($info->{parameters}, $args); + my $param = PVE::JSONSchema::get_options($info->{parameters}, $args); print Dumper($param); die "implement me"; @@ -49,7 +60,12 @@ sub call_method { #my $res = $conn->get("/", {}); #print to_json($res, { pretty => 1, canonical => 1}); -my $cmd = shift || print_usage(); +my $cli_class_handlers = { + lxc => 'PVE::APIClient::Commands::lxc', + remote => 'PVE::APIClient::Commands::remote', +}; + +my $cmd = shift || (print_usage() && exit(-1)); if ($cmd eq 'get') { my $method = 'GET'; @@ -65,8 +81,38 @@ if ($cmd eq 'get') { die "implement me"; } elsif ($cmd eq 'delete') { die "implement me"; -} elsif ($cmd eq 'remote') { - PVE::APIClient::Commands::remote->run_cli_handler(); +} elsif (my $class = $cli_class_handlers->{$cmd}) { + $class->run_cli_handler(); +} elsif ($cmd eq 'bashcomplete') { + + exit(0) if !(defined($ENV{COMP_LINE}) && defined($ENV{COMP_POINT})); + + my $cmdlist = join('|', keys %$cli_class_handlers); + 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]); + + $class->run_cli_handler(); + + } else { + + my $cmdline = substr($ENV{COMP_LINE}, 0, $ENV{COMP_POINT}); + my ($bash_command, $cur, $prev) = @ARGV; + $cmdline =~ s/$cur$//; + + my $args = PVE::Tools::split_args($cmdline); + + my @cmds = ('get', 'set', 'create', 'delete', keys %$cli_class_handlers); + if (scalar(@$args) == 1) { + foreach my $p (@cmds) { + print "$p\n" if $p =~ m/^$cur/; + } + } + } + } else { print_usage(); }