+sub verify_api {
+ my ($class) = @_;
+
+ # simply verify all registered methods
+ PVE::RESTHandler::validate_method_schemas();
+}
+
+my $get_exe_name = sub {
+ my ($class) = @_;
+
+ my $name = $class;
+ $name =~ s/^.*:://;
+ $name =~ s/_/-/g;
+
+ return $name;
+};
+
+sub generate_bash_completions {
+ my ($class) = @_;
+
+ # generate bash completion config
+
+ $exename = &$get_exe_name($class);
+
+ print <<__EOD__;
+# $exename bash completion
+
+# see http://tiswww.case.edu/php/chet/bash/FAQ
+# and __ltrim_colon_completions() in /usr/share/bash-completion/bash_completion
+# this modifies global var, but I found no better way
+COMP_WORDBREAKS=\${COMP_WORDBREAKS//:}
+
+complete -o default -C '$exename bashcomplete' $exename
+__EOD__
+}
+
+sub find_cli_class_source {
+ my ($name) = @_;
+
+ my $filename;
+
+ $name =~ s/-/_/g;
+
+ my $cpath = "PVE/CLI/${name}.pm";
+ my $spath = "PVE/Service/${name}.pm";
+ foreach my $p (@INC) {
+ foreach my $s (($cpath, $spath)) {
+ my $testfn = "$p/$s";
+ if (-f $testfn) {
+ $filename = $testfn;
+ last;
+ }
+ }
+ last if defined($filename);
+ }
+
+ return $filename;
+}
+
+sub generate_pod_manpage {
+ my ($class, $podfn) = @_;
+
+ $cli_handler_class = $class;
+
+ $exename = &$get_exe_name($class);
+
+ $podfn = find_cli_class_source($exename) if !defined($podfn);
+
+ die "unable to find source for class '$class'" if !$podfn;
+
+ no strict 'refs';
+ my $def = ${"${class}::cmddef"};
+
+ if (ref($def) eq 'ARRAY') {
+ print_simple_pod_manpage($podfn, @$def);
+ } else {
+ $cmddef = $def;
+
+ $cmddef->{help} = [ __PACKAGE__, 'help', ['cmd'] ];
+
+ print_pod_manpage($podfn);
+ }
+}
+
+sub generate_asciidoc_synopsys {
+ my ($class) = @_;
+
+ $cli_handler_class = $class;
+
+ $exename = &$get_exe_name($class);
+
+ no strict 'refs';
+ my $def = ${"${class}::cmddef"};
+
+ if (ref($def) eq 'ARRAY') {
+ print_simple_asciidoc_synopsys(@$def);
+ } else {
+ $cmddef = $def;
+
+ $cmddef->{help} = [ __PACKAGE__, 'help', ['cmd'] ];
+
+ print_asciidoc_synopsys();
+ }
+}
+
+my $handle_cmd = sub {
+ my ($def, $cmdname, $cmd, $args, $pwcallback, $podfn, $preparefunc, $stringfilemap) = @_;