6 use lib
'/usr/share/pve-client';
13 use PVE
::APIClient
::LWP
;
14 use PVE
::APIClient
::Helpers
;
15 use PVE
::APIClient
::Commands
::remote
;
16 use PVE
::APIClient
::Commands
::list
;
17 use PVE
::APIClient
::Commands
::lxc
;
18 use PVE
::APIClient
::Commands
::help
;
23 my ($path, $method, $args) = @_;
25 die "missing API path\n" if !defined($path);
27 my $info = PVE
::APIClient
::Helpers
::lookup_api_method
($path, $method);
28 my $param = PVE
::JSONSchema
::get_options
($info->{parameters
}, $args);
35 my $cli_class_handlers = {
36 list
=> 'PVE::APIClient::Commands::list',
37 lxc
=> 'PVE::APIClient::Commands::lxc',
38 remote
=> 'PVE::APIClient::Commands::remote',
39 help
=> 'PVE::APIClient::Commands::help',
44 PVE
::APIClient
::Commands
::help-
>help({});
55 if (my $method = $method_map->{$cmd}) {
57 if (scalar(@ARGV) && $ARGV[0] !~ m/^\-/) {
60 my $res = call_method
($path, $method, \
@ARGV);
62 } elsif (my $class = $cli_class_handlers->{$cmd}) {
63 $class->run_cli_handler();
64 } elsif ($cmd eq 'bashcomplete') {
66 exit(0) if !(defined($ENV{COMP_LINE
}) && defined($ENV{COMP_POINT
}));
68 my $cmdlist = join('|', keys %$cli_class_handlers);
69 if ($ENV{COMP_LINE
} =~ m/^(.*pveclient\s+($cmdlist)\s+)(.*)$/) {
71 my $class = $cli_class_handlers->{$cmd} || die "internal error";
72 $ENV{COMP_LINE
} = "pveclient $3";
73 $ENV{COMP_POINT
} = length($ENV{COMP_LINE
});
74 @ARGV = ('bashcomplete', 'pveclient', $ARGV[1], $ARGV[2]);
76 $class->run_cli_handler();
80 my $cmdline = substr($ENV{COMP_LINE
}, 0, $ENV{COMP_POINT
});
81 my ($bash_command, $cur, $prev) = @ARGV;
82 $cmdline =~ s/\Q$cur\E$//;
84 my $args = PVE
::Tools
::split_args
($cmdline);
86 my @cmds = (keys %$method_map, keys %$cli_class_handlers);
87 if (scalar(@$args) == 1) {
88 foreach my $p (@cmds) {
89 print "$p\n" if $p =~ m/^$cur/;
91 } elsif (scalar(@$args) == 2) {
92 if (my $method = $method_map->{$args->[1]}) {
93 PVE
::APIClient
::Helpers
::complete_api_path
($cur);
95 } elsif (scalar(@$args) >= 3) {
96 my $path = $args->[2];
97 if (my $method = $method_map->{$args->[1]}) {
98 if (my $info = PVE
::APIClient
::Helpers
::lookup_api_method
($path, $method, 1)) {
99 my $prop = $info->{parameters
}->{properties
};
100 PVE
::APIClient
::Helpers
::complete_api_call_options
($method, $prop, $prev, $cur, $args);
106 } elsif ($cmd eq 'packagedepends') {
107 # experimental code to print required perl packages
109 my $dir = Cwd
::getcwd
;
111 foreach my $k (keys %INC) {
112 my $file = abs_path
($INC{$k});
113 next if $file =~ m/^\Q$dir\E/;
114 my $res = `dpkg -S '$file'`;
115 if ($res && $res =~ m/^(\S+): $file$/) {
116 my $debian_package = $1;
117 $debian_package =~ s/:amd64$//;
118 $packages->{$debian_package} = 1;
120 die "unable to find package for '$file'\n";
123 print join("\n", sort(keys %$packages)) . "\n";
125 PVE
::APIClient
::Commands
::help-
>help({});