[pve-devel] [RFC pve-common v2 2/2] new schema property addStandardCliParameters

Dietmar Maurer dietmar at proxmox.com
Tue Jul 24 11:42:33 CEST 2018


Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
 src/PVE/CLIHandler.pm  | 8 +++++++-
 src/PVE/JSONSchema.pm  | 5 +++++
 src/PVE/RESTHandler.pm | 5 +++--
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/src/PVE/CLIHandler.pm b/src/PVE/CLIHandler.pm
index 7145707..ef641e9 100644
--- a/src/PVE/CLIHandler.pm
+++ b/src/PVE/CLIHandler.pm
@@ -406,7 +406,13 @@ my $print_bash_completion = sub {
 
     my $info = $class->map_method_by_name($name);
 
-    my $prop = $info->{parameters}->{properties};
+    my $prop = { %{$info->{parameters}->{properties}} }; # copy
+    if ($info->{addStandardCliParameters}) {
+	my $std_cli_opts = $PVE::RESTHandler::standard_output_options;
+	foreach my $opt (keys %$std_cli_opts) {
+	    $prop->{$opt} = $std_cli_opts->{$opt};
+	}
+    }
 
     my $print_parameter_completion = sub {
 	my ($pname) = @_;
diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm
index c9a9b1e..ec74e7c 100644
--- a/src/PVE/JSONSchema.pm
+++ b/src/PVE/JSONSchema.pm
@@ -1280,6 +1280,11 @@ my $method_schema = {
 	    type =>  'string',
 	    description => "path for URL matching (uri template)",
 	},
+        addStandardCliParameters => {
+            type => 'boolean',
+            description => "Automatically add standard parameters for CLI command (--quiet, --output-format, ...).",
+            optional => 1,
+        },
         fragmentDelimiter => {
             type => 'string',
 	    description => "A ways to override the default fragment delimiter '/'. This onyl works on a whole sub-class. You can set this to the empty string to match the whole rest of the URI.",            
diff --git a/src/PVE/RESTHandler.pm b/src/PVE/RESTHandler.pm
index 1d6b206..951e7d7 100644
--- a/src/PVE/RESTHandler.pm
+++ b/src/PVE/RESTHandler.pm
@@ -220,7 +220,8 @@ sub validate_method_schemas {
 
 	foreach my $info (@$ma) {
 	    PVE::JSONSchema::validate_method_info($info);
-	    if ($info->{parameters} && (my $pdef = $info->{parameters}->{properties})) {
+	    if ($info->{addStandardCliParameters} && $info->{parameters} &&
+		(my $pdef = $info->{parameters}->{properties})) {
 		foreach my $opt (keys %$standard_output_options) {
 		    if (defined($pdef->{$opt})) {
 			die "detected overwriten standard CLI parameter '$opt' in ${class}->$info->{name}\n";
@@ -795,7 +796,7 @@ sub cli_handler {
     my $info = $self->map_method_by_name($name);
     $options //= {};
 
-    my $add_stdopts = $options->{'std-output-opts'};
+    my $add_stdopts = $info->{addStandardCliParameters};
 
     my $res;
     eval {
-- 
2.11.0




More information about the pve-devel mailing list