[pve-devel] [PATCH common v2 3/3] Only add output_parameters to commands with output

Stoiko Ivanov s.ivanov at proxmox.com
Mon Jul 16 20:59:00 CEST 2018


Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
 src/PVE/CLIHandler.pm  | 17 +++++++++--------
 src/PVE/RESTHandler.pm | 15 ++++++++++-----
 2 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/src/PVE/CLIHandler.pm b/src/PVE/CLIHandler.pm
index 5744daf..a446f8c 100644
--- a/src/PVE/CLIHandler.pm
+++ b/src/PVE/CLIHandler.pm
@@ -200,12 +200,13 @@ sub generate_usage_str {
 	    foreach my $cmd (&$sortfunc($def)) {
 
 		if (ref($def->{$cmd}) eq 'ARRAY') {
-		    my ($class, $name, $arg_param, $fixed_param) = @{$def->{$cmd}};
+		    my ($class, $name, $arg_param, $fixed_param, $output_sub) = @{$def->{$cmd}};
 
 		    $str .= $separator if $oldclass && $oldclass ne $class;
 		    $str .= $indent;
 		    $str .= $class->usage_str($name, "$prefix $cmd", $arg_param,
-		                              $fixed_param, $format, $param_cb);
+					    $fixed_param, $format, $param_cb,
+					    $output_sub);
 		    $oldclass = $class;
 
 		} elsif (defined($def->{$cmd}->{alias}) && ($format eq 'asciidoc')) {
@@ -224,11 +225,12 @@ sub generate_usage_str {
 
 	    }
 	} else {
-	    my ($class, $name, $arg_param, $fixed_param) = @$def;
+	    my ($class, $name, $arg_param, $fixed_param, $output_sub) = @$def;
 	    $abort->("unknown command '$cmd'") if !$class;
 
 	    $str .= $indent;
-	    $str .= $class->usage_str($name, $prefix, $arg_param, $fixed_param, $format, $param_cb);
+	    $str .= $class->usage_str($name, $prefix, $arg_param, $fixed_param,
+				    $format, $param_cb, $output_sub);
 	}
 	return $str;
     };
@@ -395,7 +397,7 @@ my $print_bash_completion = sub {
 
     my $skip_param = {};
 
-    my ($class, $name, $arg_param, $uri_param) = @$def;
+    my ($class, $name, $arg_param, $uri_param, $output_sub) = @$def;
     $arg_param //= [];
     $uri_param //= {};
 
@@ -405,9 +407,8 @@ my $print_bash_completion = sub {
     map { $skip_param->{$_} = 1; } keys %$uri_param;
 
     my $info = $class->map_method_by_name($name);
-
     my $param = $info->{parameters};
-    $param = PVE::RESTHandler::add_standard_output_parameters($info->{parameters});
+    $param = PVE::RESTHandler::add_standard_output_parameters($info->{parameters}) if defined($output_sub);
     my $prop = $param->{properties};
 
     my $print_parameter_completion = sub {
@@ -552,7 +553,7 @@ my $handle_cmd  = sub {
     my ($class, $name, $arg_param, $uri_param, $outsub) = @{$def || []};
     $abort->("unknown command '$cmd_str'") if !$class;
 
-    my $options = PVE::CLIFormatter::query_terminal_options({});
+    my $options = PVE::CLIFormatter::query_terminal_options({}) if defined($outsub);
 
     my $res = $class->cli_handler($cmd_str, $name, $cmd_args, $arg_param, $uri_param, $param_cb, $options);
 
diff --git a/src/PVE/RESTHandler.pm b/src/PVE/RESTHandler.pm
index 377249d..91be661 100644
--- a/src/PVE/RESTHandler.pm
+++ b/src/PVE/RESTHandler.pm
@@ -579,13 +579,18 @@ my $compute_param_mapping_hash = sub {
 #   'asciidoc' ... generate asciidoc for man pages (like 'full')
 # $param_cb ... mapping for string parameters to file path parameters
 sub getopt_usage {
-    my ($info, $prefix, $arg_param, $fixed_param, $format, $param_cb) = @_;
+    my ($info, $prefix, $arg_param, $fixed_param, $format, $param_cb, $output_sub) = @_;
 
     $format = 'long' if !$format;
 
     my $schema = $info->{parameters};
     my $name = $info->{name};
-    my $prop = add_standard_output_parameters($schema)->{properties};
+    my $prop;
+    if (defined($output_sub)) {
+	$prop = add_standard_output_parameters($schema)->{properties};
+    } else {
+	$prop = $schema->{properties};
+    }
 
     my $out = '';
 
@@ -681,11 +686,11 @@ sub getopt_usage {
 }
 
 sub usage_str {
-    my ($self, $name, $prefix, $arg_param, $fixed_param, $format, $param_cb) = @_;
+    my ($self, $name, $prefix, $arg_param, $fixed_param, $format, $param_cb, $output_sub) = @_;
 
     my $info = $self->map_method_by_name($name);
 
-    return getopt_usage($info, $prefix, $arg_param, $fixed_param, $format, $param_cb);
+    return getopt_usage($info, $prefix, $arg_param, $fixed_param, $format, $param_cb, $output_sub);
 }
 
 # generate docs from JSON schema properties
@@ -798,7 +803,7 @@ sub cli_handler {
     eval {
 	my $param_map = {};
 	$param_map = $compute_param_mapping_hash->($param_cb->($name)) if $param_cb;
-	my $schema = add_standard_output_parameters($info->{parameters});
+	my $schema = add_standard_output_parameters($info->{parameters}) if defined($options);
 	my $param = PVE::JSONSchema::get_options($schema, $args, $arg_param, $fixed_param, $param_map);
 
 	foreach my $opt (keys %$standard_output_options) {
-- 
2.11.0





More information about the pve-devel mailing list