]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/RESTHandler.pm
print defaulttxt as sprintf parameter
[pve-common.git] / src / PVE / RESTHandler.pm
index e395b95d5c6ea02a1f63b8c50e96440d71191755..75d5d2e6dcfc5460ecc8524b8dc505005b4340c2 100644 (file)
@@ -23,13 +23,13 @@ our $standard_output_options = {
        description => "Do not show column headers (for 'text' format).",
        type => 'boolean',
        optional => 1,
-       default => 1,
+       default => 0,
     },
     noborder => {
        description => "Do not draw borders (for 'text' format).",
        type => 'boolean',
        optional => 1,
-       default => 1,
+       default => 0,
     },
     quiet => {
         description => "Suppress printing results.",
@@ -45,7 +45,7 @@ our $standard_output_options = {
 };
 
 sub api_clone_schema {
-    my ($schema) = @_;
+    my ($schema, $no_typetext) = @_;
 
     my $res = {};
     my $ref = ref($schema);
@@ -71,7 +71,7 @@ sub api_clone_schema {
            my $tmp = ref($pd) ? clone($pd) : $pd;
            # NOTE: add typetext property for more complex types, to
            # make the web api viewer code simpler
-           if (!(defined($tmp->{enum}) || defined($tmp->{pattern}))) {
+           if (!$no_typetext && !(defined($tmp->{enum}) || defined($tmp->{pattern}))) {
                my $typetext = PVE::JSONSchema::schema_get_type_text($tmp);
                if ($tmp->{type} && ($tmp->{type} ne $typetext)) {
                    $tmp->{typetext} = $typetext;
@@ -143,6 +143,8 @@ sub api_dump_full {
                    } else {
                        if ($k eq 'parameters') {
                            $data->{$k} = api_clone_schema($d);
+                       } elsif ($k eq 'returns') {
+                           $data->{$k} = api_clone_schema($d, 1);
                        } else {
                            $data->{$k} = ref($d) ? clone($d) : $d;
                        }
@@ -536,7 +538,7 @@ my $get_property_description = sub {
            die "unknown style '$style'";
        }
 
-       my $tmp = sprintf "  %-10s %s$defaulttxt\n", $display_name, "$type_text";
+       my $tmp = sprintf "  %-10s %s%s\n", $display_name, "$type_text", "$defaulttxt";
        my $indend = "             ";
 
        $res .= Text::Wrap::wrap('', $indend, ($tmp));
@@ -624,6 +626,16 @@ sub getopt_usage {
        }
     }
 
+    # also remove $standard_output_options from $prop (pvesh, pveclient)
+    if ($prop->{'output-format'}) {
+       $has_output_format_option = 1;
+       foreach my $key (keys %$prop) {
+           if ($standard_output_options->{$key}) {
+               delete $prop->{$key};
+           }
+       }
+    }
+
     my $out = '';
 
     my $arg_hash = {};