6 use lib
'/usr/share/pve-client';
13 use PVE
::APIClient
::LWP
;
14 use PVE
::APIClient
::Helpers
;
15 use PVE
::APIClient
::Commands
::config
;
16 use PVE
::APIClient
::Commands
::remote
;
17 use PVE
::APIClient
::Commands
::list
;
18 use PVE
::APIClient
::Commands
::lxc
;
19 use PVE
::APIClient
::Commands
::help
;
24 my ($path, $method, $args) = @_;
26 die "missing API path\n" if !defined($path);
28 my $info = PVE
::APIClient
::Helpers
::lookup_api_method
($path, $method);
29 my $param = PVE
::JSONSchema
::get_options
($info->{parameters
}, $args);
36 my $cli_class_handlers = {
37 list
=> 'PVE::APIClient::Commands::list',
38 lxc
=> 'PVE::APIClient::Commands::lxc',
39 remote
=> 'PVE::APIClient::Commands::remote',
40 config
=> 'PVE::APIClient::Commands::config',
41 help
=> 'PVE::APIClient::Commands::help',
46 PVE
::APIClient
::Commands
::help-
>help({});
57 if (my $method = $method_map->{$cmd}) {
59 if (scalar(@ARGV) && $ARGV[0] !~ m/^\-/) {
62 my $res = call_method
($path, $method, \
@ARGV);
64 } elsif (my $class = $cli_class_handlers->{$cmd}) {
65 $class->run_cli_handler();
66 } elsif ($cmd eq 'bashcomplete') {
68 exit(0) if !(defined($ENV{COMP_LINE
}) && defined($ENV{COMP_POINT
}));
70 my $cmdlist = join('|', keys %$cli_class_handlers);
71 if ($ENV{COMP_LINE
} =~ m/^(.*pveclient\s+($cmdlist)\s+)(.*)$/) {
73 my $class = $cli_class_handlers->{$cmd} || die "internal error";
75 if ($cmd eq 'list') { # simple commands
76 $ENV{COMP_LINE
} = "pveclient $3";
77 $ENV{COMP_POINT
} = length($ENV{COMP_LINE
});
78 @ARGV = ('bashcomplete', 'pveclient', $ARGV[1], $ARGV[2]);
80 $ENV{COMP_LINE
} = "pveclient $3";
81 $ENV{COMP_POINT
} = length($ENV{COMP_LINE
});
82 @ARGV = ('bashcomplete', 'pveclient', $ARGV[1], $ARGV[2]);
84 $class->run_cli_handler();
88 my $cmdline = substr($ENV{COMP_LINE
}, 0, $ENV{COMP_POINT
});
89 my ($bash_command, $cur, $prev) = @ARGV;
90 $cmdline =~ s/\Q$cur\E$//;
92 my $args = PVE
::Tools
::split_args
($cmdline);
94 my @cmds = (keys %$method_map, keys %$cli_class_handlers);
95 if (scalar(@$args) == 1) {
96 foreach my $p (@cmds) {
97 print "$p\n" if $p =~ m/^$cur/;
99 } elsif (scalar(@$args) == 2) {
100 if (my $method = $method_map->{$args->[1]}) {
101 PVE
::APIClient
::Helpers
::complete_api_path
($cur);
103 } elsif (scalar(@$args) >= 3) {
104 my $path = $args->[2];
105 if (my $method = $method_map->{$args->[1]}) {
106 if (my $info = PVE
::APIClient
::Helpers
::lookup_api_method
($path, $method, 1)) {
107 my $prop = $info->{parameters
}->{properties
};
108 PVE
::APIClient
::Helpers
::complete_api_call_options
($method, $prop, $prev, $cur, $args);
114 } elsif ($cmd eq 'packagedepends') {
115 # experimental code to print required perl packages
117 my $dir = Cwd
::getcwd
;
119 foreach my $k (keys %INC) {
120 my $file = abs_path
($INC{$k});
121 next if $file =~ m/^\Q$dir\E/;
122 my $res = `dpkg -S '$file'`;
123 if ($res && $res =~ m/^(\S+): $file$/) {
124 my $debian_package = $1;
125 $debian_package =~ s/:amd64$//;
126 $packages->{$debian_package} = 1;
128 die "unable to find package for '$file'\n";
131 print join("\n", sort(keys %$packages)) . "\n";
133 PVE
::APIClient
::Commands
::help-
>help({});