X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=src%2FPVE%2FCLIHandler.pm;h=c2d34387ac87c4a9331d229f6064cbe1e5625498;hb=53c255218ebec327f881a479a7be1e04646ae2e9;hp=149353797238ef481e135fafb9e65b51259a21bf;hpb=e4a1d8e240c18f363f9f91003d01ee07be24ee21;p=pve-common.git diff --git a/src/PVE/CLIHandler.pm b/src/PVE/CLIHandler.pm index 1493537..c2d3438 100644 --- a/src/PVE/CLIHandler.pm +++ b/src/PVE/CLIHandler.pm @@ -8,6 +8,7 @@ use PVE::SafeSyslog; use PVE::Exception qw(raise raise_param_exc); use PVE::RESTHandler; use PVE::PodParser; +use PVE::INotify; use base qw(PVE::RESTHandler); @@ -110,6 +111,46 @@ __PACKAGE__->register_method ({ }}); +sub print_simple_asciidoc_synopsys { + my ($class, $name, $arg_param, $uri_param) = @_; + + die "not initialized" if !$cli_handler_class; + + my $pwcallback = $cli_handler_class->can('read_password'); + + my $synopsis = "*${name}* `help`\n\n"; + + $synopsis .= $class->usage_str($name, $name, $arg_param, $uri_param, 'asciidoc', $pwcallback); + + return $synopsis; +} + +sub print_asciidoc_synopsys { + + die "not initialized" if !($cmddef && $exename && $cli_handler_class); + + my $pwcallback = $cli_handler_class->can('read_password'); + + my $synopsis = ""; + + $synopsis .= "*${exename}* ` [ARGS] [OPTIONS]`\n\n"; + + my $oldclass; + foreach my $cmd (sort keys %$cmddef) { + my ($class, $name, $arg_param, $uri_param) = @{$cmddef->{$cmd}}; + my $str = $class->usage_str($name, "$exename $cmd", $arg_param, + $uri_param, 'asciidoc', $pwcallback); + $synopsis .= "\n" if $oldclass && $oldclass ne $class; + + $synopsis .= "$str\n\n"; + $oldclass = $class; + } + + $synopsis .= "\n"; + + return $synopsis; +} + sub print_simple_pod_manpage { my ($podfn, $class, $name, $arg_param, $uri_param) = @_; @@ -389,6 +430,27 @@ sub generate_pod_manpage { } } +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) = @_;