]>
Commit | Line | Data |
---|---|---|
e143e9d8 DM |
1 | package PVE::CLIHandler; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
d8053c08 | 5 | use Data::Dumper; |
e143e9d8 | 6 | |
93ddd7bc | 7 | use PVE::SafeSyslog; |
e143e9d8 DM |
8 | use PVE::Exception qw(raise raise_param_exc); |
9 | use PVE::RESTHandler; | |
10 | use PVE::PodParser; | |
881eb755 | 11 | use PVE::INotify; |
e143e9d8 DM |
12 | |
13 | use base qw(PVE::RESTHandler); | |
14 | ||
15 | my $cmddef; | |
16 | my $exename; | |
891b798d | 17 | my $cli_handler_class; |
e143e9d8 DM |
18 | |
19 | my $expand_command_name = sub { | |
20 | my ($def, $cmd) = @_; | |
21 | ||
22 | if (!$def->{$cmd}) { | |
23 | my $expanded; | |
24 | for my $k (keys(%$def)) { | |
25 | if ($k =~ m/^$cmd/) { | |
26 | if ($expanded) { | |
27 | $expanded = undef; # more than one match | |
28 | last; | |
29 | } else { | |
30 | $expanded = $k; | |
31 | } | |
32 | } | |
33 | } | |
34 | $cmd = $expanded if $expanded; | |
35 | } | |
36 | return $cmd; | |
37 | }; | |
38 | ||
edf3d572 DM |
39 | my $complete_command_names = sub { |
40 | my $res = []; | |
41 | ||
42 | return if ref($cmddef) ne 'HASH'; | |
43 | ||
44 | foreach my $cmd (keys %$cmddef) { | |
45 | next if $cmd eq 'help'; | |
46 | push @$res, $cmd; | |
47 | } | |
48 | ||
49 | return $res; | |
50 | }; | |
51 | ||
e143e9d8 DM |
52 | __PACKAGE__->register_method ({ |
53 | name => 'help', | |
54 | path => 'help', | |
55 | method => 'GET', | |
56 | description => "Get help about specified command.", | |
57 | parameters => { | |
58 | additionalProperties => 0, | |
59 | properties => { | |
60 | cmd => { | |
61 | description => "Command name", | |
62 | type => 'string', | |
63 | optional => 1, | |
edf3d572 | 64 | completion => $complete_command_names, |
e143e9d8 DM |
65 | }, |
66 | verbose => { | |
67 | description => "Verbose output format.", | |
68 | type => 'boolean', | |
69 | optional => 1, | |
70 | }, | |
71 | }, | |
72 | }, | |
73 | returns => { type => 'null' }, | |
74 | ||
75 | code => sub { | |
76 | my ($param) = @_; | |
77 | ||
891b798d | 78 | die "not initialized" if !($cmddef && $exename && $cli_handler_class); |
e143e9d8 DM |
79 | |
80 | my $cmd = $param->{cmd}; | |
81 | ||
82 | my $verbose = defined($cmd) && $cmd; | |
83 | $verbose = $param->{verbose} if defined($param->{verbose}); | |
84 | ||
85 | if (!$cmd) { | |
86 | if ($verbose) { | |
87 | print_usage_verbose(); | |
88 | } else { | |
89 | print_usage_short(\*STDOUT); | |
90 | } | |
91 | return undef; | |
92 | } | |
93 | ||
94 | $cmd = &$expand_command_name($cmddef, $cmd); | |
95 | ||
96 | my ($class, $name, $arg_param, $uri_param) = @{$cmddef->{$cmd} || []}; | |
97 | ||
98 | raise_param_exc({ cmd => "no such command '$cmd'"}) if !$class; | |
99 | ||
891b798d | 100 | my $pwcallback = $cli_handler_class->can('read_password'); |
e143e9d8 | 101 | |
891b798d DM |
102 | my $str = $class->usage_str($name, "$exename $cmd", $arg_param, $uri_param, |
103 | $verbose ? 'full' : 'short', $pwcallback); | |
e143e9d8 DM |
104 | if ($verbose) { |
105 | print "$str\n"; | |
106 | } else { | |
107 | print "USAGE: $str\n"; | |
108 | } | |
109 | ||
110 | return undef; | |
111 | ||
112 | }}); | |
113 | ||
fe3f1fde DM |
114 | sub print_simple_asciidoc_synopsys { |
115 | my ($class, $name, $arg_param, $uri_param) = @_; | |
116 | ||
117 | die "not initialized" if !$cli_handler_class; | |
118 | ||
119 | my $pwcallback = $cli_handler_class->can('read_password'); | |
120 | ||
121 | my $synopsis = "*${name}* `help`\n\n"; | |
122 | ||
123 | $synopsis .= $class->usage_str($name, $name, $arg_param, $uri_param, 'asciidoc', $pwcallback); | |
124 | ||
125 | return $synopsis; | |
126 | } | |
127 | ||
128 | sub print_asciidoc_synopsys { | |
129 | ||
130 | die "not initialized" if !($cmddef && $exename && $cli_handler_class); | |
131 | ||
132 | my $pwcallback = $cli_handler_class->can('read_password'); | |
133 | ||
134 | my $synopsis = ""; | |
135 | ||
136 | $synopsis .= "*${exename}* `<COMMAND> [ARGS] [OPTIONS]`\n\n"; | |
137 | ||
138 | my $oldclass; | |
139 | foreach my $cmd (sort keys %$cmddef) { | |
140 | my ($class, $name, $arg_param, $uri_param) = @{$cmddef->{$cmd}}; | |
141 | my $str = $class->usage_str($name, "$exename $cmd", $arg_param, | |
142 | $uri_param, 'asciidoc', $pwcallback); | |
143 | $synopsis .= "\n" if $oldclass && $oldclass ne $class; | |
144 | ||
145 | $synopsis .= "$str\n\n"; | |
146 | $oldclass = $class; | |
147 | } | |
148 | ||
149 | $synopsis .= "\n"; | |
150 | ||
151 | return $synopsis; | |
152 | } | |
153 | ||
7fe1f565 DM |
154 | sub print_simple_pod_manpage { |
155 | my ($podfn, $class, $name, $arg_param, $uri_param) = @_; | |
156 | ||
2fff84d9 DM |
157 | die "not initialized" if !$cli_handler_class; |
158 | ||
891b798d DM |
159 | my $pwcallback = $cli_handler_class->can('read_password'); |
160 | ||
7fe1f565 | 161 | my $synopsis = " $name help\n\n"; |
891b798d | 162 | my $str = $class->usage_str($name, $name, $arg_param, $uri_param, 'long', $pwcallback); |
7fe1f565 DM |
163 | $str =~ s/^USAGE://; |
164 | $str =~ s/\n/\n /g; | |
165 | $synopsis .= $str; | |
166 | ||
167 | my $parser = PVE::PodParser->new(); | |
168 | $parser->{include}->{synopsis} = $synopsis; | |
169 | $parser->parse_from_file($podfn); | |
170 | } | |
171 | ||
e143e9d8 DM |
172 | sub print_pod_manpage { |
173 | my ($podfn) = @_; | |
174 | ||
891b798d | 175 | die "not initialized" if !($cmddef && $exename && $cli_handler_class); |
e143e9d8 DM |
176 | die "no pod file specified" if !$podfn; |
177 | ||
891b798d DM |
178 | my $pwcallback = $cli_handler_class->can('read_password'); |
179 | ||
e143e9d8 DM |
180 | my $synopsis = ""; |
181 | ||
182 | $synopsis .= " $exename <COMMAND> [ARGS] [OPTIONS]\n\n"; | |
183 | ||
184 | my $style = 'full'; # or should we use 'short'? | |
185 | my $oldclass; | |
186 | foreach my $cmd (sorted_commands()) { | |
187 | my ($class, $name, $arg_param, $uri_param) = @{$cmddef->{$cmd}}; | |
891b798d DM |
188 | my $str = $class->usage_str($name, "$exename $cmd", $arg_param, |
189 | $uri_param, $style, $pwcallback); | |
e143e9d8 DM |
190 | $str =~ s/^USAGE: //; |
191 | ||
192 | $synopsis .= "\n" if $oldclass && $oldclass ne $class; | |
193 | $str =~ s/\n/\n /g; | |
194 | $synopsis .= " $str\n\n"; | |
195 | $oldclass = $class; | |
196 | } | |
197 | ||
198 | $synopsis .= "\n"; | |
199 | ||
200 | my $parser = PVE::PodParser->new(); | |
201 | $parser->{include}->{synopsis} = $synopsis; | |
202 | $parser->parse_from_file($podfn); | |
203 | } | |
204 | ||
205 | sub print_usage_verbose { | |
206 | ||
891b798d DM |
207 | die "not initialized" if !($cmddef && $exename && $cli_handler_class); |
208 | ||
209 | my $pwcallback = $cli_handler_class->can('read_password'); | |
e143e9d8 DM |
210 | |
211 | print "USAGE: $exename <COMMAND> [ARGS] [OPTIONS]\n\n"; | |
212 | ||
213 | foreach my $cmd (sort keys %$cmddef) { | |
214 | my ($class, $name, $arg_param, $uri_param) = @{$cmddef->{$cmd}}; | |
891b798d DM |
215 | my $str = $class->usage_str($name, "$exename $cmd", $arg_param, $uri_param, |
216 | 'full', $pwcallback); | |
e143e9d8 DM |
217 | print "$str\n\n"; |
218 | } | |
219 | } | |
220 | ||
221 | sub sorted_commands { | |
222 | return sort { ($cmddef->{$a}->[0] cmp $cmddef->{$b}->[0]) || ($a cmp $b)} keys %$cmddef; | |
223 | } | |
224 | ||
225 | sub print_usage_short { | |
226 | my ($fd, $msg) = @_; | |
227 | ||
891b798d DM |
228 | die "not initialized" if !($cmddef && $exename && $cli_handler_class); |
229 | ||
230 | my $pwcallback = $cli_handler_class->can('read_password'); | |
e143e9d8 DM |
231 | |
232 | print $fd "ERROR: $msg\n" if $msg; | |
233 | print $fd "USAGE: $exename <COMMAND> [ARGS] [OPTIONS]\n"; | |
234 | ||
235 | my $oldclass; | |
236 | foreach my $cmd (sorted_commands()) { | |
237 | my ($class, $name, $arg_param, $uri_param) = @{$cmddef->{$cmd}}; | |
891b798d | 238 | my $str = $class->usage_str($name, "$exename $cmd", $arg_param, $uri_param, 'short', $pwcallback); |
e143e9d8 DM |
239 | print $fd "\n" if $oldclass && $oldclass ne $class; |
240 | print $fd " $str"; | |
241 | $oldclass = $class; | |
242 | } | |
243 | } | |
244 | ||
d8053c08 DM |
245 | my $print_bash_completion = sub { |
246 | my ($cmddef, $simple_cmd, $bash_command, $cur, $prev) = @_; | |
247 | ||
248 | my $debug = 0; | |
249 | ||
250 | return if !(defined($cur) && defined($prev) && defined($bash_command)); | |
251 | return if !defined($ENV{COMP_LINE}); | |
252 | return if !defined($ENV{COMP_POINT}); | |
253 | ||
254 | my $cmdline = substr($ENV{COMP_LINE}, 0, $ENV{COMP_POINT}); | |
255 | print STDERR "\nCMDLINE: $ENV{COMP_LINE}\n" if $debug; | |
256 | ||
58d9e664 DM |
257 | my $args = PVE::Tools::split_args($cmdline); |
258 | my $pos = scalar(@$args) - 2; | |
d8053c08 DM |
259 | $pos += 1 if $cmdline =~ m/\s+$/; |
260 | ||
261 | print STDERR "CMDLINE:$pos:$cmdline\n" if $debug; | |
262 | ||
263 | return if $pos < 0; | |
264 | ||
265 | my $print_result = sub { | |
266 | foreach my $p (@_) { | |
267 | print "$p\n" if $p =~ m/^$cur/; | |
268 | } | |
269 | }; | |
270 | ||
271 | my $cmd; | |
272 | if ($simple_cmd) { | |
273 | $cmd = $simple_cmd; | |
274 | } else { | |
275 | if ($pos == 0) { | |
276 | &$print_result(keys %$cmddef); | |
277 | return; | |
278 | } | |
58d9e664 | 279 | $cmd = $args->[1]; |
d8053c08 DM |
280 | } |
281 | ||
282 | my $def = $cmddef->{$cmd}; | |
283 | return if !$def; | |
284 | ||
285 | print STDERR "CMDLINE1:$pos:$cmdline\n" if $debug; | |
286 | ||
287 | my $skip_param = {}; | |
288 | ||
289 | my ($class, $name, $arg_param, $uri_param) = @$def; | |
290 | $arg_param //= []; | |
291 | $uri_param //= {}; | |
292 | ||
d90a2fd0 DM |
293 | $arg_param = [ $arg_param ] if !ref($arg_param); |
294 | ||
d8053c08 DM |
295 | map { $skip_param->{$_} = 1; } @$arg_param; |
296 | map { $skip_param->{$_} = 1; } keys %$uri_param; | |
297 | ||
298 | my $fpcount = scalar(@$arg_param); | |
299 | ||
300 | my $info = $class->map_method_by_name($name); | |
301 | ||
302 | my $schema = $info->{parameters}; | |
303 | my $prop = $schema->{properties}; | |
304 | ||
305 | my $print_parameter_completion = sub { | |
306 | my ($pname) = @_; | |
307 | my $d = $prop->{$pname}; | |
308 | if ($d->{completion}) { | |
309 | my $vt = ref($d->{completion}); | |
310 | if ($vt eq 'CODE') { | |
58d9e664 | 311 | my $res = $d->{completion}->($cmd, $pname, $cur, $args); |
d8053c08 DM |
312 | &$print_result(@$res); |
313 | } | |
314 | } elsif ($d->{type} eq 'boolean') { | |
315 | &$print_result('0', '1'); | |
316 | } elsif ($d->{enum}) { | |
317 | &$print_result(@{$d->{enum}}); | |
318 | } | |
319 | }; | |
320 | ||
321 | # positional arguments | |
322 | $pos += 1 if $simple_cmd; | |
323 | if ($fpcount && $pos <= $fpcount) { | |
324 | my $pname = $arg_param->[$pos -1]; | |
325 | &$print_parameter_completion($pname); | |
326 | return; | |
327 | } | |
328 | ||
329 | my @option_list = (); | |
330 | foreach my $key (keys %$prop) { | |
331 | next if $skip_param->{$key}; | |
332 | push @option_list, "--$key"; | |
333 | } | |
334 | ||
335 | if ($cur =~ m/^-/) { | |
336 | &$print_result(@option_list); | |
337 | return; | |
338 | } | |
339 | ||
340 | if ($prev =~ m/^--?(.+)$/ && $prop->{$1}) { | |
341 | my $pname = $1; | |
342 | &$print_parameter_completion($pname); | |
343 | return; | |
344 | } | |
345 | ||
346 | &$print_result(@option_list); | |
347 | }; | |
348 | ||
1f130ba6 DM |
349 | sub verify_api { |
350 | my ($class) = @_; | |
351 | ||
352 | # simply verify all registered methods | |
353 | PVE::RESTHandler::validate_method_schemas(); | |
354 | } | |
355 | ||
8f3712f8 DM |
356 | my $get_exe_name = sub { |
357 | my ($class) = @_; | |
358 | ||
359 | my $name = $class; | |
360 | $name =~ s/^.*:://; | |
361 | $name =~ s/_/-/g; | |
362 | ||
363 | return $name; | |
364 | }; | |
365 | ||
c45707a0 DM |
366 | sub generate_bash_completions { |
367 | my ($class) = @_; | |
368 | ||
369 | # generate bash completion config | |
370 | ||
8f3712f8 | 371 | $exename = &$get_exe_name($class); |
c45707a0 DM |
372 | |
373 | print <<__EOD__; | |
374 | # $exename bash completion | |
375 | ||
376 | # see http://tiswww.case.edu/php/chet/bash/FAQ | |
377 | # and __ltrim_colon_completions() in /usr/share/bash-completion/bash_completion | |
378 | # this modifies global var, but I found no better way | |
379 | COMP_WORDBREAKS=\${COMP_WORDBREAKS//:} | |
380 | ||
e4a1d8e2 | 381 | complete -o default -C '$exename bashcomplete' $exename |
c45707a0 DM |
382 | __EOD__ |
383 | } | |
384 | ||
7fe1f565 | 385 | sub find_cli_class_source { |
8f3712f8 | 386 | my ($name) = @_; |
7fe1f565 DM |
387 | |
388 | my $filename; | |
389 | ||
8f3712f8 DM |
390 | $name =~ s/-/_/g; |
391 | ||
392 | my $cpath = "PVE/CLI/${name}.pm"; | |
393 | my $spath = "PVE/Service/${name}.pm"; | |
7fe1f565 | 394 | foreach my $p (@INC) { |
edf3d572 DM |
395 | foreach my $s (($cpath, $spath)) { |
396 | my $testfn = "$p/$s"; | |
397 | if (-f $testfn) { | |
398 | $filename = $testfn; | |
399 | last; | |
400 | } | |
7fe1f565 | 401 | } |
edf3d572 | 402 | last if defined($filename); |
7fe1f565 DM |
403 | } |
404 | ||
405 | return $filename; | |
406 | } | |
407 | ||
1f130ba6 DM |
408 | sub generate_pod_manpage { |
409 | my ($class, $podfn) = @_; | |
410 | ||
891b798d DM |
411 | $cli_handler_class = $class; |
412 | ||
8f3712f8 | 413 | $exename = &$get_exe_name($class); |
1f130ba6 | 414 | |
7fe1f565 | 415 | $podfn = find_cli_class_source($exename) if !defined($podfn); |
1f130ba6 DM |
416 | |
417 | die "unable to find source for class '$class'" if !$podfn; | |
418 | ||
7fe1f565 DM |
419 | no strict 'refs'; |
420 | my $def = ${"${class}::cmddef"}; | |
421 | ||
bb958629 | 422 | if (ref($def) eq 'ARRAY') { |
7fe1f565 DM |
423 | print_simple_pod_manpage($podfn, @$def); |
424 | } else { | |
425 | $cmddef = $def; | |
edf3d572 DM |
426 | |
427 | $cmddef->{help} = [ __PACKAGE__, 'help', ['cmd'] ]; | |
428 | ||
7fe1f565 DM |
429 | print_pod_manpage($podfn); |
430 | } | |
1f130ba6 DM |
431 | } |
432 | ||
fe3f1fde DM |
433 | sub generate_asciidoc_synopsys { |
434 | my ($class) = @_; | |
435 | ||
436 | $cli_handler_class = $class; | |
437 | ||
438 | $exename = &$get_exe_name($class); | |
439 | ||
440 | no strict 'refs'; | |
441 | my $def = ${"${class}::cmddef"}; | |
442 | ||
443 | if (ref($def) eq 'ARRAY') { | |
444 | print_simple_asciidoc_synopsys(@$def); | |
445 | } else { | |
446 | $cmddef = $def; | |
447 | ||
448 | $cmddef->{help} = [ __PACKAGE__, 'help', ['cmd'] ]; | |
449 | ||
450 | print_asciidoc_synopsys(); | |
451 | } | |
452 | } | |
453 | ||
891b798d | 454 | my $handle_cmd = sub { |
8e3e9929 | 455 | my ($def, $cmdname, $cmd, $args, $pwcallback, $podfn, $preparefunc) = @_; |
e143e9d8 DM |
456 | |
457 | $cmddef = $def; | |
458 | $exename = $cmdname; | |
459 | ||
460 | $cmddef->{help} = [ __PACKAGE__, 'help', ['cmd'] ]; | |
461 | ||
462 | if (!$cmd) { | |
463 | print_usage_short (\*STDERR, "no command specified"); | |
464 | exit (-1); | |
465 | } elsif ($cmd eq 'verifyapi') { | |
466 | PVE::RESTHandler::validate_method_schemas(); | |
467 | return; | |
468 | } elsif ($cmd eq 'printmanpod') { | |
edf3d572 | 469 | $podfn = find_cli_class_source($exename) if !defined($podfn); |
e143e9d8 DM |
470 | print_pod_manpage($podfn); |
471 | return; | |
d8053c08 DM |
472 | } elsif ($cmd eq 'bashcomplete') { |
473 | &$print_bash_completion($cmddef, 0, @$args); | |
474 | return; | |
e143e9d8 DM |
475 | } |
476 | ||
8e3e9929 WB |
477 | &$preparefunc() if $preparefunc; |
478 | ||
e143e9d8 DM |
479 | $cmd = &$expand_command_name($cmddef, $cmd); |
480 | ||
481 | my ($class, $name, $arg_param, $uri_param, $outsub) = @{$cmddef->{$cmd} || []}; | |
482 | ||
483 | if (!$class) { | |
484 | print_usage_short (\*STDERR, "unknown command '$cmd'"); | |
485 | exit (-1); | |
486 | } | |
487 | ||
488 | my $prefix = "$exename $cmd"; | |
489 | my $res = $class->cli_handler($prefix, $name, \@ARGV, $arg_param, $uri_param, $pwcallback); | |
2026f4b5 DM |
490 | |
491 | &$outsub($res) if $outsub; | |
891b798d | 492 | }; |
2026f4b5 | 493 | |
891b798d | 494 | my $handle_simple_cmd = sub { |
7fe1f565 | 495 | my ($def, $args, $pwcallback, $podfn, $preparefunc) = @_; |
2026f4b5 DM |
496 | |
497 | my ($class, $name, $arg_param, $uri_param, $outsub) = @{$def}; | |
498 | die "no class specified" if !$class; | |
499 | ||
d8053c08 | 500 | if (scalar(@$args) >= 1) { |
2026f4b5 DM |
501 | if ($args->[0] eq 'help') { |
502 | my $str = "USAGE: $name help\n"; | |
891b798d | 503 | $str .= $class->usage_str($name, $name, $arg_param, $uri_param, 'long', $pwcallback); |
2026f4b5 DM |
504 | print STDERR "$str\n\n"; |
505 | return; | |
d8053c08 DM |
506 | } elsif ($args->[0] eq 'bashcomplete') { |
507 | shift @$args; | |
508 | &$print_bash_completion({ $name => $def }, $name, @$args); | |
509 | return; | |
2026f4b5 DM |
510 | } elsif ($args->[0] eq 'verifyapi') { |
511 | PVE::RESTHandler::validate_method_schemas(); | |
512 | return; | |
513 | } elsif ($args->[0] eq 'printmanpod') { | |
7fe1f565 DM |
514 | $podfn = find_cli_class_source($name) if !defined($podfn); |
515 | print_simple_pod_manpage($podfn, @$def); | |
2026f4b5 DM |
516 | return; |
517 | } | |
e143e9d8 | 518 | } |
2026f4b5 | 519 | |
7fe1f565 DM |
520 | &$preparefunc() if $preparefunc; |
521 | ||
2026f4b5 DM |
522 | my $res = $class->cli_handler($name, $name, \@ARGV, $arg_param, $uri_param, $pwcallback); |
523 | ||
524 | &$outsub($res) if $outsub; | |
891b798d DM |
525 | }; |
526 | ||
527 | sub run_cli { | |
528 | my ($class, $pwcallback, $podfn, $preparefunc) = @_; | |
529 | ||
530 | # Note: "depreciated function run_cli - use run_cli_handler instead"; | |
531 | ||
532 | die "password callback is no longer supported" if $pwcallback; | |
533 | ||
5ae87c41 | 534 | run_cli_handler($class, podfn => $podfn, prepare => $preparefunc); |
891b798d DM |
535 | } |
536 | ||
537 | sub run_cli_handler { | |
538 | my ($class, %params) = @_; | |
539 | ||
540 | $cli_handler_class = $class; | |
541 | ||
542 | $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin'; | |
543 | ||
aa9b9af5 DM |
544 | foreach my $key (keys %params) { |
545 | next if $key eq 'podfn'; | |
5ae87c41 | 546 | next if $key eq 'prepare'; |
5ffbe2f1 | 547 | next if $key eq 'no_init'; # used by lxc hooks |
aa9b9af5 DM |
548 | die "unknown parameter '$key'"; |
549 | } | |
550 | ||
891b798d | 551 | my $podfn = $params{podfn}; |
5ae87c41 | 552 | my $preparefunc = $params{prepare}; |
5ffbe2f1 | 553 | my $no_init = $params{no_init}; |
891b798d DM |
554 | |
555 | my $pwcallback = $class->can('read_password'); | |
556 | ||
557 | $exename = &$get_exe_name($class); | |
558 | ||
559 | initlog($exename); | |
560 | ||
561 | if ($class !~ m/^PVE::Service::/) { | |
562 | die "please run as root\n" if $> != 0; | |
563 | ||
5ffbe2f1 | 564 | PVE::INotify::inotify_init() if !$no_init; |
891b798d DM |
565 | |
566 | my $rpcenv = PVE::RPCEnvironment->init('cli'); | |
5ffbe2f1 | 567 | $rpcenv->init_request() if !$no_init; |
891b798d DM |
568 | $rpcenv->set_language($ENV{LANG}); |
569 | $rpcenv->set_user('root@pam'); | |
570 | } | |
571 | ||
572 | no strict 'refs'; | |
573 | my $def = ${"${class}::cmddef"}; | |
574 | ||
575 | if (ref($def) eq 'ARRAY') { | |
576 | &$handle_simple_cmd($def, \@ARGV, $pwcallback, $podfn, $preparefunc); | |
577 | } else { | |
578 | $cmddef = $def; | |
579 | my $cmd = shift @ARGV; | |
580 | &$handle_cmd($cmddef, $exename, $cmd, \@ARGV, $pwcallback, $podfn, $preparefunc); | |
581 | } | |
582 | ||
583 | exit 0; | |
e143e9d8 DM |
584 | } |
585 | ||
586 | 1; |