X-Git-Url: https://git.proxmox.com/?p=pve-client.git;a=blobdiff_plain;f=pveclient;h=cbcc113778ed75611be6baf7248df2cbaa257575;hp=b12e5f6a553603064be4376906e7d17d1bc8f9c4;hb=07c6b1d4cf07a07ac955cbce0bb1668a4718b56c;hpb=55d17e7e1afc13816e8cd92f928fc65ba60e6820 diff --git a/pveclient b/pveclient index b12e5f6..cbcc113 100755 --- a/pveclient +++ b/pveclient @@ -8,6 +8,7 @@ use Cwd 'abs_path'; use Data::Dumper; use PVE::APIClient::JSONSchema qw(register_standard_option get_standard_option); +use PVE::APIClient::RESTHandler; use PVE::APIClient::CLIFormatter; use PVE::APIClient::CLIHandler; use PVE::APIClient::PTY; @@ -29,12 +30,12 @@ sub call_api_method { my $path = PVE::APIClient::Tools::extract_param($param, 'api_path'); die "missing API path\n" if !defined($path); + my $stdopts = PVE::APIClient::RESTHandler::extract_standard_output_properties($param); + PVE::APIClient::CLIFormatter::query_terminal_options($stdopts); + 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 = {}; @@ -46,7 +47,9 @@ sub call_api_method { die "undefined result" if !defined($res); die "undefined result data" if !exists($res->{data}); - return $res->{data}; + my $data = $res->{data}; + + PVE::APIClient::CLIFormatter::print_api_result($data, $info->{returns}, undef, $stdopts); } use base qw(PVE::APIClient::CLIHandler); @@ -81,7 +84,6 @@ if ($cmd && $cmd eq 'packagedepends') { } my $path_properties = {}; -my $path_returns = { type => 'null' }; my $api_path_property = { description => "API path.", @@ -100,23 +102,11 @@ if (my $info = PVE::APIClient::Helpers::extract_path_info($uri_param)) { next if defined($uri_param->{$key}); $path_properties->{$key} = $info->{parameters}->{properties}->{$key}; } - $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 $options = PVE::APIClient::CLIFormatter::query_terminal_options({}); - - PVE::APIClient::CLIFormatter::print_api_result($format, $data, $path_returns, undef, $options); -}; - __PACKAGE__->register_method ({ name => 'pveclient_get', path => 'pveclient_get', @@ -124,13 +114,15 @@ __PACKAGE__->register_method ({ description => "Call API GET on .", parameters => { additionalProperties => 0, - properties => $path_properties, + properties => PVE::APIClient::RESTHandler::add_standard_output_properties($path_properties), }, - returns => $path_returns, + returns => { type => 'null' }, code => sub { my ($param) = @_; - return call_api_method('GET', $param); + call_api_method('GET', $param); + + return undef; }}); __PACKAGE__->register_method ({ @@ -140,13 +132,15 @@ __PACKAGE__->register_method ({ description => "Call API PUT on .", parameters => { additionalProperties => 0, - properties => $path_properties, + properties => PVE::APIClient::RESTHandler::add_standard_output_properties($path_properties), }, - returns => $path_returns, + returns => { type => 'null' }, code => sub { my ($param) = @_; - return call_api_method('PUT', $param); + call_api_method('PUT', $param); + + return undef; }}); __PACKAGE__->register_method ({ @@ -156,13 +150,15 @@ __PACKAGE__->register_method ({ description => "Call API POST on .", parameters => { additionalProperties => 0, - properties => $path_properties, + properties => PVE::APIClient::RESTHandler::add_standard_output_properties($path_properties), }, - returns => $path_returns, + returns => { type => 'null' }, code => sub { my ($param) = @_; - return call_api_method('PUSH', $param); + call_api_method('PUSH', $param); + + return undef; }}); __PACKAGE__->register_method ({ @@ -172,13 +168,15 @@ __PACKAGE__->register_method ({ description => "Call API DELETE on .", parameters => { additionalProperties => 0, - properties => $path_properties, + properties => PVE::APIClient::RESTHandler::add_standard_output_properties($path_properties), }, - returns => $path_returns, + returns => { type => 'null' }, code => sub { my ($param) = @_; - return call_api_method('DELETE', $param); + call_api_method('DELETE', $param); + + return undef; }}); __PACKAGE__->register_method ({ @@ -264,10 +262,10 @@ our $cmddef = { api => { usage => [ __PACKAGE__, 'pveclient_usage', ['api_path']], - get => [ __PACKAGE__, 'pveclient_get', ['remote', 'api_path'], {}, $format_result ], - set => [ __PACKAGE__, 'pveclient_set', ['remote', 'api_path'], {}, $format_result ], - create => [ __PACKAGE__, 'pveclient_create', ['remote', 'api_path'], {}, $format_result ], - delete => [ __PACKAGE__, 'pveclient_delete', ['remote', 'api_path'], {}, $format_result ], + get => [ __PACKAGE__, 'pveclient_get', ['remote', 'api_path']], + set => [ __PACKAGE__, 'pveclient_set', ['remote', 'api_path']], + create => [ __PACKAGE__, 'pveclient_create', ['remote', 'api_path']], + delete => [ __PACKAGE__, 'pveclient_delete', ['remote', 'api_path']], }, };