]> git.proxmox.com Git - pve-client.git/commitdiff
use new features from pve-common
authorDietmar Maurer <dietmar@proxmox.com>
Wed, 11 Jul 2018 08:36:16 +0000 (10:36 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 11 Jul 2018 08:36:16 +0000 (10:36 +0200)
PVE/APIClient/Commands/config.pm
PVE/APIClient/Commands/list.pm
PVE/APIClient/Commands/remote.pm
PVE/APIClient/Helpers.pm
pveclient

index a5171fbf8af43753ae268da500cec413ab484d7c..b4316d80550ecce889504b0b2ee5bf2a26f11c38 100644 (file)
@@ -9,6 +9,7 @@ use PVE::APIClient::JSONSchema qw(get_standard_option);
 use PVE::APIClient::Tools qw(extract_param);
 use PVE::APIClient::Config;
 
+use PVE::APIClient::CLIFormatter;
 use PVE::APIClient::CLIHandler;
 
 use base qw(PVE::APIClient::CLIHandler);
@@ -23,6 +24,7 @@ __PACKAGE__->register_method ({
     description => "Dump default configuration.",
     parameters => {
        additionalProperties => 0,
+       properties => {},
     },
     returns => {
        type => 'object',
@@ -90,7 +92,13 @@ __PACKAGE__->register_method ({
 
 our $cmddef = {
     set => [ __PACKAGE__, 'set',],
-    list => [__PACKAGE__, 'list', undef, undef, sub { PVE::APIClient::Helpers::print_result(@_);}],
+    list => [__PACKAGE__, 'list', undef, undef,
+            sub {
+                my ($data, $schema, $options) = @_;
+
+                PVE::APIClient::CLIFormatter::print_api_result($data, $schema, undef, $options);
+            }
+       ],
 };
 
 1;
index 10a8f7c5afd0831b994d17c2966aefc8e4693dea..1fb90bf1a5924cd207f8383bdd80818e81740bd1 100644 (file)
@@ -30,7 +30,6 @@ __PACKAGE__->register_method ({
        additionalProperties => 0,
        properties => {
            remote => get_standard_option('pveclient-remote-name'),
-           'format' => get_standard_option('pve-output-format'),
        },
     },
     returns => {
@@ -43,9 +42,6 @@ __PACKAGE__->register_method ({
     code => sub {
        my ($param) = @_;
 
-       my $format = PVE::APIClient::Tools::extract_param($param, 'format');
-       PVE::APIClient::Helpers::set_output_format($format);
-
        my $config = PVE::APIClient::Config->load();
        my $conn = PVE::APIClient::Config->remote_conn($config, $param->{remote});
 
@@ -54,7 +50,8 @@ __PACKAGE__->register_method ({
 
 
 our $cmddef = [ __PACKAGE__, 'list', ['remote'], {}, sub {
-    PVE::APIClient::Helpers::print_ordered_result($list_returns_properties, @_);
+    my ($data, $schema, $options) = @_;
+    PVE::APIClient::Helpers::print_ordered_result($list_returns_properties, $data, $schema, $options);
 }];
 
 1;
index 2e5337aa2c9be3a2837b5019ac7a18d93f09ca79..bd13e2b103f42dcfe530a06870a8710565eb213f 100644 (file)
@@ -35,9 +35,7 @@ __PACKAGE__->register_method ({
     description => "List remotes from your config file.",
     parameters => {
        additionalProperties => 0,
-       properties => {
-           'format' => get_standard_option('pve-output-format'),
-       },
+       properties => {},
     },
     returns => {
        type => 'array',
@@ -49,9 +47,6 @@ __PACKAGE__->register_method ({
     code => sub {
        my ($param) = @_;
 
-       my $format = PVE::APIClient::Tools::extract_param($param, 'format');
-       PVE::APIClient::Helpers::set_output_format($format);
-
        my $config = PVE::APIClient::Config->load();
 
        my $res = [];
@@ -212,7 +207,8 @@ our $cmddef = {
     set => [ __PACKAGE__, 'remote_set', ['name']],
     delete => [ __PACKAGE__, 'remote_delete', ['name']],
     list => [__PACKAGE__, 'remote_list', undef, {}, sub {
-       PVE::APIClient::Helpers::print_ordered_result($remote_list_returns_properties, @_);
+       my ($data, $schema, $options) = @_;
+       PVE::APIClient::Helpers::print_ordered_result($remote_list_returns_properties, $data, $schema, $options);
     }],
 };
 
index 9d599d6cd27b0b3f83d0ca688468aa9e8733f430..106e497790512d65f068f92af1ba53d21b0f2ca9 100644 (file)
@@ -27,23 +27,6 @@ our $method_map = {
     delete => 'DELETE',
 };
 
-my $default_output_format = 'text';
-my $client_output_format =  $default_output_format;
-
-sub set_output_format {
-    my ($format) = @_;
-
-    if (!defined($format)) {
-       $client_output_format =  $default_output_format;
-    } else {
-       $client_output_format =  $format;
-    }
-}
-
-sub get_output_format {
-    return $client_output_format;
-}
-
 my $__real_remove_formats; $__real_remove_formats = sub {
     my ($properties) = @_;
 
@@ -405,23 +388,12 @@ sub extract_even_elements {
     return [ grep { ($ind++ % 2) == 0 } @$list ];
 }
 
-sub print_result {
-    my ($data, $result_schema, $param_order) = @_;
-
-    my $options = {};
-    PVE::APIClient::CLIFormatter::query_terminal_options($options);
-
-    my $format = get_output_format();
-    PVE::APIClient::CLIFormatter::print_api_result(
-       $format, $data, $result_schema, $param_order, $options);
-}
-
 sub print_ordered_result {
-    my ($property_list, $data, $result_schema) = @_;
+    my ($property_list, $data, $result_schema, $options) = @_;
 
     my $param_order = extract_even_elements($property_list);
 
-    print_result($data, $result_schema, $param_order);
+    PVE::APIClient::CLIFormatter::print_api_result($data, $result_schema, $param_order, $options);
 }
 
 1;
index b12e5f6a553603064be4376906e7d17d1bc8f9c4..c6c48c8bc0722fe5c3354b5c8eb20aa20a6c94b9 100755 (executable)
--- a/pveclient
+++ b/pveclient
@@ -24,7 +24,7 @@ use PVE::APIClient::Commands::GuestStatus;
 use JSON;
 
 sub call_api_method {
-    my ($method, $param) = @_;
+    my ($method, $param, $options) = @_;
 
     my $path = PVE::APIClient::Tools::extract_param($param, 'api_path');
     die "missing API path\n" if !defined($path);
@@ -32,9 +32,6 @@ sub call_api_method {
     my $remote = PVE::APIClient::Tools::extract_param($param, 'remote');
     die "missing remote\n" if !defined($remote);
 
-    my $format = PVE::APIClient::Tools::extract_param($param, 'format');
-    PVE::APIClient::Helpers::set_output_format($format);
-
     my $config = PVE::APIClient::Config->load();
 
     my $uri_param = {};
@@ -103,18 +100,14 @@ if (my $info = PVE::APIClient::Helpers::extract_path_info($uri_param)) {
     $path_returns = $info->{returns};
 }
 
-$path_properties->{format} = get_standard_option('pve-output-format'),
 $path_properties->{remote} = get_standard_option('pveclient-remote-name');
 $path_properties->{api_path} = $api_path_property;
 
 my $format_result = sub {
-    my ($data) = @_;
-
-    my $format = PVE::APIClient::Helpers::get_output_format();
+    my ($data, $schema, $options) = @_;
 
-    my $options = PVE::APIClient::CLIFormatter::query_terminal_options({});
-
-    PVE::APIClient::CLIFormatter::print_api_result($format, $data, $path_returns, undef, $options);
+    # NOTE; we need to use $path_returns instead of $schema
+    PVE::APIClient::CLIFormatter::print_api_result($data, $path_returns, undef, $options);
 };
 
 __PACKAGE__->register_method ({
@@ -128,9 +121,9 @@ __PACKAGE__->register_method ({
     },
     returns => $path_returns,
     code => sub {
-       my ($param) = @_;
+       my ($param, $options) = @_;
 
-       return call_api_method('GET', $param);
+       return call_api_method('GET', $param, $options);
     }});
 
 __PACKAGE__->register_method ({
@@ -144,9 +137,9 @@ __PACKAGE__->register_method ({
     },
     returns => $path_returns,
     code => sub {
-       my ($param) = @_;
+       my ($param, $options) = @_;
 
-       return call_api_method('PUT', $param);
+       return call_api_method('PUT', $param, $options);
     }});
 
 __PACKAGE__->register_method ({
@@ -160,9 +153,9 @@ __PACKAGE__->register_method ({
     },
     returns => $path_returns,
     code => sub {
-       my ($param) = @_;
+       my ($param, $options) = @_;
 
-       return call_api_method('PUSH', $param);
+       return call_api_method('PUSH', $param, $options);
     }});
 
 __PACKAGE__->register_method ({
@@ -176,9 +169,9 @@ __PACKAGE__->register_method ({
     },
     returns => $path_returns,
     code => sub {
-       my ($param) = @_;
+       my ($param, $options) = @_;
 
-       return call_api_method('DELETE', $param);
+       return call_api_method('DELETE', $param, $options);
     }});
 
 __PACKAGE__->register_method ({