]> git.proxmox.com Git - pve-common.git/blob - src/PVE/CLIHandler.pm
9933df704e34c0b9a616a5160716efd0bad6fe5a
[pve-common.git] / src / PVE / CLIHandler.pm
1 package PVE::CLIHandler;
2
3 use strict;
4 use warnings;
5 use JSON;
6
7 use PVE::SafeSyslog;
8 use PVE::Exception qw(raise raise_param_exc);
9 use PVE::RESTHandler;
10 use PVE::PTY;
11 use PVE::INotify;
12
13 use base qw(PVE::RESTHandler);
14
15 # $cmddef defines which (sub)commands are available in a specific CLI class.
16 # A real command is always an array consisting of its class, name, array of
17 # position fixed (required) parameters and hash of predefined parameters when
18 # mapping a CLI command t o an API call. Optionally an output method can be
19 # passed at the end, e.g., for formatting or transformation purpose.
20 #
21 # [class, name, fixed_params, API_pre-set params, output_sub ]
22 #
23 # In case of so called 'simple commands', the $cmddef can be also just an
24 # array.
25 #
26 # Examples:
27 # $cmddef = {
28 # command => [ 'PVE::API2::Class', 'command', [ 'arg1', 'arg2' ], { node => $nodename } ],
29 # do => {
30 # this => [ 'PVE::API2::OtherClass', 'method', [ 'arg1' ], undef, sub {
31 # my ($res) = @_;
32 # print "$res\n";
33 # }],
34 # that => [ 'PVE::API2::OtherClass', 'subroutine' [] ],
35 # },
36 # dothat => { alias => 'do that' },
37 # }
38 my $cmddef;
39 my $exename;
40 my $cli_handler_class;
41
42 my $standard_mappings = {
43 'pve-password' => {
44 name => 'password',
45 desc => '<password>',
46 interactive => 1,
47 func => sub {
48 my ($value) = @_;
49 return $value if $value;
50 return PVE::PTY::get_confirmed_password();
51 },
52 },
53 };
54 sub get_standard_mapping {
55 my ($name, $base) = @_;
56
57 my $std = $standard_mappings->{$name};
58 die "no such standard mapping '$name'\n" if !$std;
59
60 my $res = $base || {};
61
62 foreach my $opt (keys %$std) {
63 next if defined($res->{$opt});
64 $res->{$opt} = $std->{$opt};
65 }
66
67 return $res;
68 }
69
70 my $assert_initialized = sub {
71 my @caller = caller;
72 die "$caller[0]:$caller[2] - not initialized\n"
73 if !($cmddef && $exename && $cli_handler_class);
74 };
75
76 my $abort = sub {
77 my ($reason, $cmd) = @_;
78 print_usage_short (\*STDERR, $reason, $cmd);
79 exit (-1);
80 };
81
82 my $expand_command_name = sub {
83 my ($def, $cmd) = @_;
84
85 return $cmd if exists $def->{$cmd}; # command is already complete
86
87 my $is_alias = sub { ref($_[0]) eq 'HASH' && exists($_[0]->{alias}) };
88 my @expanded = grep { /^\Q$cmd\E/ && !$is_alias->($def->{$_}) } keys %$def;
89
90 return $expanded[0] if scalar(@expanded) == 1; # enforce exact match
91
92 return undef;
93 };
94
95 my $get_commands = sub {
96 my $def = shift // die "no command definition passed!";
97 return [ grep { !(ref($def->{$_}) eq 'HASH' && defined($def->{$_}->{alias})) } sort keys %$def ];
98 };
99
100 my $complete_command_names = sub { $get_commands->($cmddef) };
101
102 # traverses the command definition using the $argv array, resolving one level
103 # of aliases.
104 # Returns the matching (sub) command and its definition, and argument array for
105 # this (sub) command and a hash where we marked which (sub) commands got
106 # expanded (e.g. st => status) while traversing
107 sub resolve_cmd {
108 my ($argv, $is_alias) = @_;
109
110 my ($def, $cmd) = ($cmddef, $argv);
111 my $cmdstr = $exename;
112
113 if (ref($argv) eq 'ARRAY') {
114 my $expanded_last_arg;
115 my $last_arg_id = scalar(@$argv) - 1;
116
117 for my $i (0..$last_arg_id) {
118 $cmd = $expand_command_name->($def, $argv->[$i]);
119 if (defined($cmd)) {
120 # If the argument was expanded (or was already complete) and it
121 # is the final argument, tell our caller about it:
122 $expanded_last_arg = $cmd if $i == $last_arg_id;
123 } else {
124 # Otherwise continue with the unexpanded version of it.
125 $cmd = $argv->[$i];
126 }
127 $cmdstr .= " $cmd";
128 $def = $def->{$cmd};
129 last if !defined($def);
130
131 if (ref($def) eq 'ARRAY') {
132 # could expand to a real command, rest of $argv are its arguments
133 my $cmd_args = [ @$argv[$i+1..$last_arg_id] ];
134 return ($cmd, $def, $cmd_args, $expanded_last_arg, $cmdstr);
135 }
136
137 if (defined($def->{alias})) {
138 die "alias loop detected for '$cmd'" if $is_alias; # avoids cycles
139 # replace aliased (sub)command with the expanded aliased command
140 splice @$argv, $i, 1, split(/ +/, $def->{alias});
141 return resolve_cmd($argv, 1);
142 }
143 }
144 # got either a special command (bashcomplete, verifyapi) or an unknown
145 # cmd, just return first entry as cmd and the rest of $argv as cmd_arg
146 my $cmd_args = [ @$argv[1..$last_arg_id] ];
147 return ($argv->[0], $def, $cmd_args, $expanded_last_arg, $cmdstr);
148 }
149 return ($cmd, $def, undef, undef, $cmdstr);
150 }
151
152 sub generate_usage_str {
153 my ($format, $cmd, $indent, $separator, $sortfunc) = @_;
154
155 $assert_initialized->();
156 die 'format required' if !$format;
157
158 $sortfunc //= sub { sort keys %{$_[0]} };
159 $separator //= '';
160 $indent //= '';
161
162 my $read_password_func = $cli_handler_class->can('read_password');
163 my $param_mapping_func = $cli_handler_class->can('param_mapping') ||
164 $cli_handler_class->can('string_param_file_mapping');
165
166 my ($subcmd, $def, undef, undef, $cmdstr) = resolve_cmd($cmd);
167 $abort->("unknown command '$cmdstr'") if !defined($def) && ref($cmd) eq 'ARRAY';
168
169 my $generate;
170 $generate = sub {
171 my ($indent, $separator, $def, $prefix) = @_;
172
173 my $str = '';
174 if (ref($def) eq 'HASH') {
175 my $oldclass = undef;
176 foreach my $cmd (&$sortfunc($def)) {
177
178 if (ref($def->{$cmd}) eq 'ARRAY') {
179 my ($class, $name, $arg_param, $fixed_param) = @{$def->{$cmd}};
180
181 $str .= $separator if $oldclass && $oldclass ne $class;
182 $str .= $indent;
183 $str .= $class->usage_str($name, "$prefix $cmd", $arg_param,
184 $fixed_param, $format,
185 $read_password_func, $param_mapping_func);
186 $oldclass = $class;
187
188 } elsif (defined($def->{$cmd}->{alias}) && ($format eq 'asciidoc')) {
189
190 $str .= "*$prefix $cmd*\n\nAn alias for '$exename $def->{$cmd}->{alias}'.\n\n";
191
192 } else {
193 next if $def->{$cmd}->{alias};
194
195 my $substr = $generate->($indent, $separator, $def->{$cmd}, "$prefix $cmd");
196 if ($substr) {
197 $substr .= $separator if $substr !~ /\Q$separator\E{2}/;
198 $str .= $substr;
199 }
200 }
201
202 }
203 } else {
204 my ($class, $name, $arg_param, $fixed_param) = @$def;
205 $abort->("unknown command '$cmd'") if !$class;
206
207 $str .= $indent;
208 $str .= $class->usage_str($name, $prefix, $arg_param, $fixed_param, $format,
209 $read_password_func, $param_mapping_func);
210 }
211 return $str;
212 };
213
214 return $generate->($indent, $separator, $def, $cmdstr);
215 }
216
217 __PACKAGE__->register_method ({
218 name => 'help',
219 path => 'help',
220 method => 'GET',
221 description => "Get help about specified command.",
222 parameters => {
223 additionalProperties => 0,
224 properties => {
225 'extra-args' => PVE::JSONSchema::get_standard_option('extra-args', {
226 description => 'Shows help for a specific command',
227 completion => $complete_command_names,
228 }),
229 verbose => {
230 description => "Verbose output format.",
231 type => 'boolean',
232 optional => 1,
233 },
234 },
235 },
236 returns => { type => 'null' },
237
238 code => sub {
239 my ($param) = @_;
240
241 $assert_initialized->();
242
243 my $cmd = $param->{'extra-args'};
244
245 my $verbose = defined($cmd) && $cmd;
246 $verbose = $param->{verbose} if defined($param->{verbose});
247
248 if (!$cmd) {
249 if ($verbose) {
250 print_usage_verbose();
251 } else {
252 print_usage_short(\*STDOUT);
253 }
254 return undef;
255 }
256
257 my $str;
258 if ($verbose) {
259 $str = generate_usage_str('full', $cmd, '');
260 } else {
261 $str = generate_usage_str('short', $cmd, ' ' x 7);
262 }
263 $str =~ s/^\s+//;
264
265 if ($verbose) {
266 print "$str\n";
267 } else {
268 print "USAGE: $str\n";
269 }
270
271 return undef;
272
273 }});
274
275 sub print_simple_asciidoc_synopsis {
276 $assert_initialized->();
277
278 my $synopsis = "*${exename}* `help`\n\n";
279 $synopsis .= generate_usage_str('asciidoc');
280
281 return $synopsis;
282 }
283
284 sub print_asciidoc_synopsis {
285 $assert_initialized->();
286
287 my $synopsis = "";
288
289 $synopsis .= "*${exename}* `<COMMAND> [ARGS] [OPTIONS]`\n\n";
290
291 $synopsis .= generate_usage_str('asciidoc');
292
293 $synopsis .= "\n";
294
295 return $synopsis;
296 }
297
298 sub print_usage_verbose {
299 $assert_initialized->();
300
301 print "USAGE: $exename <COMMAND> [ARGS] [OPTIONS]\n\n";
302
303 my $str = generate_usage_str('full');
304
305 print "$str\n";
306 }
307
308 sub print_usage_short {
309 my ($fd, $msg, $cmd) = @_;
310
311 $assert_initialized->();
312
313 print $fd "ERROR: $msg\n" if $msg;
314 print $fd "USAGE: $exename <COMMAND> [ARGS] [OPTIONS]\n";
315
316 print {$fd} generate_usage_str('short', $cmd, ' ' x 7, "\n", sub {
317 my ($h) = @_;
318 return sort {
319 if (ref($h->{$a}) eq 'ARRAY' && ref($h->{$b}) eq 'ARRAY') {
320 # $a and $b are both real commands order them by their class
321 return $h->{$a}->[0] cmp $h->{$b}->[0] || $a cmp $b;
322 } elsif (ref($h->{$a}) eq 'ARRAY' xor ref($h->{$b}) eq 'ARRAY') {
323 # real command and subcommand mixed, put sub commands first
324 return ref($h->{$b}) eq 'ARRAY' ? -1 : 1;
325 } else {
326 # both are either from the same class or subcommands
327 return $a cmp $b;
328 }
329 } keys %$h;
330 });
331 }
332
333 my $print_bash_completion = sub {
334 my ($simple_cmd, $bash_command, $cur, $prev) = @_;
335
336 my $debug = 0;
337
338 return if !(defined($cur) && defined($prev) && defined($bash_command));
339 return if !defined($ENV{COMP_LINE});
340 return if !defined($ENV{COMP_POINT});
341
342 my $cmdline = substr($ENV{COMP_LINE}, 0, $ENV{COMP_POINT});
343 print STDERR "\nCMDLINE: $ENV{COMP_LINE}\n" if $debug;
344
345 my $args = PVE::Tools::split_args($cmdline);
346 shift @$args; # no need for program name
347 my $print_result = sub {
348 foreach my $p (@_) {
349 print "$p\n" if $p =~ m/^\Q$cur\E/;
350 }
351 };
352
353 my ($cmd, $def) = ($simple_cmd, $cmddef);
354 if (!$simple_cmd) {
355 ($cmd, $def, $args, my $expanded) = resolve_cmd($args);
356
357 if (defined($expanded) && $prev ne $expanded) {
358 print "$expanded\n";
359 return;
360 }
361
362 if (ref($def) eq 'HASH') {
363 &$print_result(@{$get_commands->($def)});
364 return;
365 }
366 }
367 return if !$def;
368
369 my $pos = scalar(@$args) - 1;
370 $pos += 1 if $cmdline =~ m/\s+$/;
371 print STDERR "pos: $pos\n" if $debug;
372 return if $pos < 0;
373
374 my $skip_param = {};
375
376 my ($class, $name, $arg_param, $uri_param) = @$def;
377 $arg_param //= [];
378 $uri_param //= {};
379
380 $arg_param = [ $arg_param ] if !ref($arg_param);
381
382 map { $skip_param->{$_} = 1; } @$arg_param;
383 map { $skip_param->{$_} = 1; } keys %$uri_param;
384
385 my $info = $class->map_method_by_name($name);
386
387 my $prop = $info->{parameters}->{properties};
388
389 my $print_parameter_completion = sub {
390 my ($pname) = @_;
391 my $d = $prop->{$pname};
392 if ($d->{completion}) {
393 my $vt = ref($d->{completion});
394 if ($vt eq 'CODE') {
395 my $res = $d->{completion}->($cmd, $pname, $cur, $args);
396 &$print_result(@$res);
397 }
398 } elsif ($d->{type} eq 'boolean') {
399 &$print_result('0', '1');
400 } elsif ($d->{enum}) {
401 &$print_result(@{$d->{enum}});
402 }
403 };
404
405 # positional arguments
406 if ($pos < scalar(@$arg_param)) {
407 my $pname = $arg_param->[$pos];
408 &$print_parameter_completion($pname);
409 return;
410 }
411
412 my @option_list = ();
413 foreach my $key (keys %$prop) {
414 next if $skip_param->{$key};
415 push @option_list, "--$key";
416 }
417
418 if ($cur =~ m/^-/) {
419 &$print_result(@option_list);
420 return;
421 }
422
423 if ($prev =~ m/^--?(.+)$/ && $prop->{$1}) {
424 my $pname = $1;
425 &$print_parameter_completion($pname);
426 return;
427 }
428
429 &$print_result(@option_list);
430 };
431
432 sub data_to_text {
433 my ($data) = @_;
434
435 return undef if !defined($data);
436
437 if (my $class = ref($data)) {
438 return to_json($data, { utf8 => 1, canonical => 1 });
439 } else {
440 return "$data";
441 }
442 }
443
444 # prints a formatted table with a title row.
445 # $formatopts is an array of hashes, with the following keys:
446 # 'key' - key of $data element to print
447 # 'title' - column title, defaults to 'key' - won't get cutoff
448 # 'cutoff' - maximal (print) length of this column values, if set
449 # the last column will never be cutoff
450 # 'default' - optional default value for the column
451 # formatopts element order defines column order (left to right)
452 # sorts the output according to the leftmost column not containing any undef
453 sub print_text_table {
454 my ($formatopts, $data) = @_;
455
456 my ($formatstring, @keys, @titles, %cutoffs, %defaults, $sort_key);
457 my $last_col = $formatopts->[$#{$formatopts}];
458
459 foreach my $col ( @$formatopts ) {
460 my ($key, $title, $cutoff) = @$col{qw(key title cutoff)};
461 $title //= $key;
462
463 push @keys, $key;
464 push @titles, $title;
465 $defaults{$key} = $col->{default} // '';
466
467 # calculate maximal print width and cutoff
468 my $titlelen = length($title);
469
470 my $longest = $titlelen;
471 my $sortable = 1;
472 foreach my $entry (@$data) {
473 my $len = length(data_to_text($entry->{$key})) // 0;
474 $longest = $len if $len > $longest;
475 $sortable = 0 if !defined($entry->{$key});
476 }
477
478 $sort_key //= $key if $sortable;
479 $cutoff = (defined($cutoff) && $cutoff < $longest) ? $cutoff : $longest;
480 $cutoffs{$key} = $cutoff;
481
482 my $printalign = $cutoff > $titlelen ? '-' : '';
483 if ($col == $last_col) {
484 $formatstring .= "%${printalign}${titlelen}s\n";
485 } else {
486 $formatstring .= "%${printalign}${cutoff}s ";
487 }
488 }
489
490 printf $formatstring, @titles;
491
492 if (defined($sort_key)){
493 @$data = sort { $a->{$sort_key} cmp $b->{$sort_key} } @$data;
494 }
495 foreach my $entry (@$data) {
496 printf $formatstring, map { substr((data_to_text($entry->{$_}) // $defaults{$_}), 0 , $cutoffs{$_}) } @keys;
497 }
498 }
499
500 # prints the result of an API GET call returning an array as a table.
501 # takes formatting information from the results property of the call
502 # if $props_to_print is provided, prints only those columns. otherwise
503 # takes all fields of the results property, with a fallback
504 # to all fields occuring in items of $data.
505 sub print_api_list {
506 my ($data, $result_schema, $props_to_print) = @_;
507
508 die "can only print object lists\n"
509 if !($result_schema->{type} eq 'array' && $result_schema->{items}->{type} eq 'object');
510
511 my $returnprops = $result_schema->{items}->{properties};
512
513 if (!defined($props_to_print)) {
514 $props_to_print = [ sort keys %$returnprops ];
515 if (!scalar(@$props_to_print)) {
516 my $all_props = {};
517 foreach my $obj (@{$data}) {
518 foreach my $key (keys %{$obj}) {
519 $all_props->{ $key } = 1;
520 }
521 }
522 $props_to_print = [ sort keys %{$all_props} ];
523 }
524 die "unable to detect list properties\n" if !scalar(@$props_to_print);
525 }
526
527 my $formatopts = [];
528 foreach my $prop ( @$props_to_print ) {
529 my $propinfo = $returnprops->{$prop};
530 my $colopts = {
531 key => $prop,
532 title => $propinfo->{title},
533 default => $propinfo->{default},
534 cutoff => $propinfo->{print_width} // $propinfo->{maxLength},
535 };
536 push @$formatopts, $colopts;
537 }
538
539 print_text_table($formatopts, $data);
540 }
541
542 sub print_api_result {
543 my ($format, $data, $result_schema, $props_to_print) = @_;
544
545 return if $result_schema->{type} eq 'null';
546
547 if ($format eq 'json') {
548 print to_json($data, {utf8 => 1, allow_nonref => 1, canonical => 1, pretty => 1 });
549 } elsif ($format eq 'text') {
550 my $type = $result_schema->{type};
551 if ($type eq 'object') {
552 if (defined($props_to_print)) {
553 foreach my $key (@$props_to_print) {
554 print $key . ": " . data_to_text($data->{$key}) . "\n";
555 }
556 } else {
557 foreach my $key (sort keys %$data) {
558 print $key . ": " . data_to_text($data->{$key}) . "\n";
559 }
560 }
561 } elsif ($type eq 'array') {
562 return if !scalar(@$data);
563 my $item_type = $result_schema->{items}->{type};
564 if ($item_type eq 'object') {
565 print_api_list($data, $result_schema, $props_to_print);
566 } else {
567 foreach my $entry (@$data) {
568 print data_to_text($entry) . "\n";
569 }
570 }
571 } else {
572 print "$data\n";
573 }
574 } else {
575 die "internal error: unknown output format"; # should not happen
576 }
577 }
578
579 sub verify_api {
580 my ($class) = @_;
581
582 # simply verify all registered methods
583 PVE::RESTHandler::validate_method_schemas();
584 }
585
586 my $get_exe_name = sub {
587 my ($class) = @_;
588
589 my $name = $class;
590 $name =~ s/^.*:://;
591 $name =~ s/_/-/g;
592
593 return $name;
594 };
595
596 sub generate_bash_completions {
597 my ($class) = @_;
598
599 # generate bash completion config
600
601 $exename = &$get_exe_name($class);
602
603 print <<__EOD__;
604 # $exename bash completion
605
606 # see http://tiswww.case.edu/php/chet/bash/FAQ
607 # and __ltrim_colon_completions() in /usr/share/bash-completion/bash_completion
608 # this modifies global var, but I found no better way
609 COMP_WORDBREAKS=\${COMP_WORDBREAKS//:}
610
611 complete -o default -C '$exename bashcomplete' $exename
612 __EOD__
613 }
614
615 sub generate_asciidoc_synopsys {
616 my ($class) = @_;
617 $class->generate_asciidoc_synopsis();
618 };
619
620 sub generate_asciidoc_synopsis {
621 my ($class) = @_;
622
623 $cli_handler_class = $class;
624
625 $exename = &$get_exe_name($class);
626
627 no strict 'refs';
628 my $def = ${"${class}::cmddef"};
629 $cmddef = $def;
630
631 if (ref($def) eq 'ARRAY') {
632 print_simple_asciidoc_synopsis();
633 } else {
634 $cmddef->{help} = [ __PACKAGE__, 'help', ['cmd'] ];
635
636 print_asciidoc_synopsis();
637 }
638 }
639
640 # overwrite this if you want to run/setup things early
641 sub setup_environment {
642 my ($class) = @_;
643
644 # do nothing by default
645 }
646
647 my $handle_cmd = sub {
648 my ($args, $read_password_func, $preparefunc, $param_mapping_func) = @_;
649
650 $cmddef->{help} = [ __PACKAGE__, 'help', ['extra-args'] ];
651
652 my ($cmd, $def, $cmd_args, undef, $cmd_str) = resolve_cmd($args);
653
654 $abort->("no command specified") if !$cmd;
655
656 # call verifyapi before setup_environment(), don't execute any real code in
657 # this case
658 if ($cmd eq 'verifyapi') {
659 PVE::RESTHandler::validate_method_schemas();
660 return;
661 }
662
663 $cli_handler_class->setup_environment();
664
665 if ($cmd eq 'bashcomplete') {
666 &$print_bash_completion(undef, @$cmd_args);
667 return;
668 }
669
670 # checked special commands, if def is still a hash we got an incomplete sub command
671 $abort->("incomplete command '$cmd_str'", $args) if ref($def) eq 'HASH';
672
673 &$preparefunc() if $preparefunc;
674
675 my ($class, $name, $arg_param, $uri_param, $outsub) = @{$def || []};
676 $abort->("unknown command '$cmd_str'") if !$class;
677
678 my $res = $class->cli_handler($cmd_str, $name, $cmd_args, $arg_param, $uri_param, $read_password_func, $param_mapping_func);
679
680 if (defined $outsub) {
681 my $result_schema = $class->map_method_by_name($name)->{returns};
682 $outsub->($res, $result_schema);
683 }
684 };
685
686 my $handle_simple_cmd = sub {
687 my ($args, $read_password_func, $preparefunc, $param_mapping_func) = @_;
688
689 my ($class, $name, $arg_param, $uri_param, $outsub) = @{$cmddef};
690 die "no class specified" if !$class;
691
692 if (scalar(@$args) >= 1) {
693 if ($args->[0] eq 'help') {
694 my $str = "USAGE: $name help\n";
695 $str .= generate_usage_str('long');
696 print STDERR "$str\n\n";
697 return;
698 } elsif ($args->[0] eq 'verifyapi') {
699 PVE::RESTHandler::validate_method_schemas();
700 return;
701 }
702 }
703
704 $cli_handler_class->setup_environment();
705
706 if (scalar(@$args) >= 1) {
707 if ($args->[0] eq 'bashcomplete') {
708 shift @$args;
709 &$print_bash_completion($name, @$args);
710 return;
711 }
712 }
713
714 &$preparefunc() if $preparefunc;
715
716 my $res = $class->cli_handler($name, $name, \@ARGV, $arg_param, $uri_param, $read_password_func, $param_mapping_func);
717
718 if (defined $outsub) {
719 my $result_schema = $class->map_method_by_name($name)->{returns};
720 $outsub->($res, $result_schema);
721 }
722 };
723
724 sub run_cli_handler {
725 my ($class, %params) = @_;
726
727 $cli_handler_class = $class;
728
729 $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
730
731 foreach my $key (keys %params) {
732 next if $key eq 'prepare';
733 next if $key eq 'no_init'; # not used anymore
734 next if $key eq 'no_rpcenv'; # not used anymore
735 die "unknown parameter '$key'";
736 }
737
738 my $preparefunc = $params{prepare};
739
740 my $read_password_func = $class->can('read_password');
741 my $param_mapping_func = $cli_handler_class->can('param_mapping') ||
742 $class->can('string_param_file_mapping');
743
744 $exename = &$get_exe_name($class);
745
746 initlog($exename);
747
748 no strict 'refs';
749 $cmddef = ${"${class}::cmddef"};
750
751 if (ref($cmddef) eq 'ARRAY') {
752 &$handle_simple_cmd(\@ARGV, $read_password_func, $preparefunc, $param_mapping_func);
753 } else {
754 &$handle_cmd(\@ARGV, $read_password_func, $preparefunc, $param_mapping_func);
755 }
756
757 exit 0;
758 }
759
760 1;