[pve-devel] [pve-common] PVE::RESTHandler::generate_usage_str - new static method to generate usage from $info

Thomas Lamprecht t.lamprecht at proxmox.com
Thu Jul 5 18:43:23 CEST 2018


On 7/5/18 11:20 AM, Dietmar Maurer wrote:
> This is useful to generate usage information with pveclient, where we do not have
> handler classes at all.
> 
> Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
> ---
>  src/PVE/RESTHandler.pm | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/src/PVE/RESTHandler.pm b/src/PVE/RESTHandler.pm
> index c303c38..d2587f6 100644
> --- a/src/PVE/RESTHandler.pm
> +++ b/src/PVE/RESTHandler.pm
> @@ -566,7 +566,7 @@ my $compute_param_mapping_hash = sub {
>  
>  # generate usage information for command line tools
>  #
> -# $name        ... the name of the method
> +# $info        ... method info
>  # $prefix      ... usually something like "$exename $cmd" ('pvesm add')
>  # $arg_param   ... list of parameters we want to get as ordered arguments 
>  #                  on the command line (or single parameter name for lists)
> @@ -577,13 +577,13 @@ my $compute_param_mapping_hash = sub {
>  #   'full'     ... text, include description
>  #   'asciidoc' ... generate asciidoc for man pages (like 'full')
>  # $param_cb ... mapping for string parameters to file path parameters
> -sub usage_str {
> -    my ($self, $name, $prefix, $arg_param, $fixed_param, $format, $param_cb) = @_;
> +sub generate_usage_str {
> +    my ($info, $prefix, $arg_param, $fixed_param, $format, $param_cb) = @_;

Hmm, we have already a generate_usage_str in CLIHandler (a child of this class),
with a different signature, It also calls this classes usage_str which then calls
a generate_usage_str, seems like a bit of an weird cycle:
(CLI) generate_usage_str -> (REST) usage_str -> (REST) generate_usage_str

I do not really have any objection, code wise the change is definitely
OK, seems just a little bit strange to me personally...

>  
>      $format = 'long' if !$format;
>  
> -    my $info = $self->map_method_by_name($name);
>      my $schema = $info->{parameters};
> +    my $name = $info->{name};
>      my $prop = $schema->{properties};
>  
>      my $out = '';
> @@ -679,6 +679,14 @@ sub usage_str {
>      return $out;
>  }
>  
> +sub usage_str {
> +    my ($self, $name, $prefix, $arg_param, $fixed_param, $format, $param_cb) = @_;
> +
> +    my $info = $self->map_method_by_name($name);
> +
> +    return generate_usage_str($info, $prefix, $arg_param, $fixed_param, $format, $param_cb);
> +}
> +
>  # generate docs from JSON schema properties
>  sub dump_properties {
>      my ($prop, $format, $style, $filterFn) = @_;
> 





More information about the pve-devel mailing list