[pve-devel] applied: [pve-common] getopt_usage: do not display $standard_output_options

Dietmar Maurer dietmar at proxmox.com
Thu Jul 26 14:29:21 CEST 2018


Instead, simply add [FORMAT_OPTIONS] to the usage string.

Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
 src/PVE/RESTHandler.pm | 73 +++++++++++++++++++++++++++++---------------------
 1 file changed, 43 insertions(+), 30 deletions(-)

diff --git a/src/PVE/RESTHandler.pm b/src/PVE/RESTHandler.pm
index 5761ee3..e395b95 100644
--- a/src/PVE/RESTHandler.pm
+++ b/src/PVE/RESTHandler.pm
@@ -17,6 +17,33 @@ my $method_path_lookup = {};
 
 our $AUTOLOAD;  # it's a package global
 
+our $standard_output_options = {
+    'output-format' => PVE::JSONSchema::get_standard_option('pve-output-format'),
+    noheader => {
+	description => "Do not show column headers (for 'text' format).",
+	type => 'boolean',
+	optional => 1,
+	default => 1,
+    },
+    noborder => {
+	description => "Do not draw borders (for 'text' format).",
+	type => 'boolean',
+	optional => 1,
+	default => 1,
+    },
+    quiet => {
+        description => "Suppress printing results.",
+        type => 'boolean',
+        optional => 1,
+    },
+    'human-readable' => {
+        description => "Call output rendering functions to produce human readable text.",
+        type => 'boolean',
+        optional => 1,
+	default => 1,
+    }
+};
+
 sub api_clone_schema {
     my ($schema) = @_;
 
@@ -586,7 +613,16 @@ sub getopt_usage {
     my $schema = $info->{parameters};
     my $name = $info->{name};
     my $prop = { %{$schema->{properties}} }; # copy
-    $prop = { %$prop, %$formatter_properties } if $formatter_properties;
+
+    my $has_output_format_option = $formatter_properties->{'output-format'} ? 1 : 0;
+
+    if ($formatter_properties) {
+	foreach my $key (keys %$formatter_properties) {
+	    if (!$standard_output_options->{$key}) {
+		$prop->{$key} = $formatter_properties->{$key};
+	    }
+	}
+    }
 
     my $out = '';
 
@@ -655,11 +691,15 @@ sub getopt_usage {
     if ($format eq 'asciidoc') {
 	$out .= "*${prefix}*";
 	$out .= " `$args`" if $args;
-	$out .= $opts ? " `[OPTIONS]`\n" : "\n";
+	$out .= " `[OPTIONS]`" if $opts;
+	$out .= " `[FORMAT_OPTIONS]`" if $has_output_format_option;
+	$out .= "\n";
     } else {
 	$out .= "USAGE: " if $format ne 'short';
 	$out .= "$prefix $args";
-	$out .= $opts ? " [OPTIONS]\n" : "\n";
+	$out .= " [OPTIONS]" if $opts;
+	$out .= " [FORMAT_OPTIONS]" if $has_output_format_option;
+	$out .= "\n";
     }
 
     return $out if $format eq 'short';
@@ -747,33 +787,6 @@ my $replace_file_names_with_contents = sub {
     return $param;
 };
 
-our $standard_output_options = {
-    'output-format' => PVE::JSONSchema::get_standard_option('pve-output-format'),
-    noheader => {
-	description => "Do not show column headers (for 'text' format).",
-	type => 'boolean',
-	optional => 1,
-	default => 1,
-    },
-    noborder => {
-	description => "Do not draw borders (for 'text' format).",
-	type => 'boolean',
-	optional => 1,
-	default => 1,
-    },
-    quiet => {
-        description => "Suppress printing results.",
-        type => 'boolean',
-        optional => 1,
-    },
-    'human-readable' => {
-        description => "Call output rendering functions to produce human readable text.",
-        type => 'boolean',
-        optional => 1,
-	default => 1,
-    }
-};
-
 sub add_standard_output_properties {
     my ($propdef, $list) = @_;
 
-- 
2.11.0




More information about the pve-devel mailing list