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";
73 if ($cmd eq 'list') { # simple commands
74 $ENV{COMP_LINE
} = "pveclient $3";
75 $ENV{COMP_POINT
} = length($ENV{COMP_LINE
});
76 @ARGV = ('bashcomplete', 'pveclient', $ARGV[1], $ARGV[2]);
78 $ENV{COMP_LINE
} = "pveclient $3";
79 $ENV{COMP_POINT
} = length($ENV{COMP_LINE
});
80 @ARGV = ('bashcomplete', 'pveclient', $ARGV[1], $ARGV[2]);
82 $class->run_cli_handler();
86 my $cmdline = substr($ENV{COMP_LINE
}, 0, $ENV{COMP_POINT
});
87 my ($bash_command, $cur, $prev) = @ARGV;
88 $cmdline =~ s/\Q$cur\E$//;
90 my $args = PVE
::Tools
::split_args
($cmdline);
92 my @cmds = (keys %$method_map, keys %$cli_class_handlers);
93 if (scalar(@$args) == 1) {
94 foreach my $p (@cmds) {
95 print "$p\n" if $p =~ m/^$cur/;
97 } elsif (scalar(@$args) == 2) {
98 if (my $method = $method_map->{$args->[1]}) {
99 PVE
::APIClient
::Helpers
::complete_api_path
($cur);
101 } elsif (scalar(@$args) >= 3) {
102 my $path = $args->[2];
103 if (my $method = $method_map->{$args->[1]}) {
104 if (my $info = PVE
::APIClient
::Helpers
::lookup_api_method
($path, $method, 1)) {
105 my $prop = $info->{parameters
}->{properties
};
106 PVE
::APIClient
::Helpers
::complete_api_call_options
($method, $prop, $prev, $cur, $args);
112 } elsif ($cmd eq 'packagedepends') {
113 # experimental code to print required perl packages
115 my $dir = Cwd
::getcwd
;
117 foreach my $k (keys %INC) {
118 my $file = abs_path
($INC{$k});
119 next if $file =~ m/^\Q$dir\E/;
120 my $res = `dpkg -S '$file'`;
121 if ($res && $res =~ m/^(\S+): $file$/) {
122 my $debian_package = $1;
123 $debian_package =~ s/:amd64$//;
124 $packages->{$debian_package} = 1;
126 die "unable to find package for '$file'\n";
129 print join("\n", sort(keys %$packages)) . "\n";
131 PVE
::APIClient
::Commands
::help-
>help({});