From: Dietmar Maurer Date: Thu, 26 Jul 2018 11:58:50 +0000 (+0200) Subject: getopt_usage: do not display $standard_output_options X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=commitdiff_plain;h=62c66c47fb838e50a468f60cabff67011a9d0fcf getopt_usage: do not display $standard_output_options Instead, simply add [FORMAT_OPTIONS] to the usage string. --- 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) = @_;