]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/RESTHandler.pm
getopt_usage: do not display $standard_output_options
[pve-common.git] / src / PVE / RESTHandler.pm
index 5761ee394c2213e38a9ff24e440e96fc6dd971f8..e395b95d5c6ea02a1f63b8c50e96440d71191755 100644 (file)
@@ -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) = @_;