+my $path_properties = {};
+my $path_returns = { type => 'null' };
+
+# dynamically update schema definition for direct API call
+# like: pveclient api <get|set|create|delete|help> <remote> <path>
+if (my $info = PVE::APIClient::Helpers::extract_path_info()) {
+ $path_properties = $info->{parameters}->{properties};
+ $path_returns = $info->{returns};
+}
+
+$path_properties->{format} = get_standard_option('pveclient-output-format'),
+$path_properties->{remote} = get_standard_option('pveclient-remote-name');
+$path_properties->{api_path} = {
+ description => "API path.",
+ type => 'string',
+ completion => sub {
+ my ($cmd, $pname, $cur, $args) = @_;
+ return PVE::APIClient::Helpers::complete_api_path($cur);
+ },
+};
+
+
+my $format_result = sub {
+ my ($data) = @_;
+
+ my $format = PVE::APIClient::Helpers::get_output_format();
+
+ return if $path_returns->{type} eq 'null';
+
+ # TODO: implement different output formats ($format)
+ print to_json($data, {utf8 => 1, allow_nonref => 1, canonical => 1, pretty => 1 });
+};
+
+__PACKAGE__->register_method ({
+ name => 'pveclient_get',
+ path => 'pveclient_get',
+ method => 'GET',
+ description => "call API GET on <path>.",
+ parameters => {
+ additionalProperties => 0,
+ properties => $path_properties,
+ },
+ returns => $path_returns,
+ code => sub {
+ my ($param) = @_;
+
+ return call_api_method('GET', $param);
+ }});
+
+__PACKAGE__->register_method ({
+ name => 'pveclient_set',
+ path => 'pveclient_set',
+ method => 'PUT',
+ description => "call API PUT on <path>.",
+ parameters => {
+ additionalProperties => 0,
+ properties => $path_properties,
+ },
+ returns => $path_returns,
+ code => sub {
+ my ($param) = @_;
+
+ return call_api_method('PUT', $param);
+ }});
+
+__PACKAGE__->register_method ({
+ name => 'pveclient_create',
+ path => 'pveclient_create',
+ method => 'PUSH',
+ description => "call API PUSH on <path>.",
+ parameters => {
+ additionalProperties => 0,
+ properties => $path_properties,
+ },
+ returns => $path_returns,
+ code => sub {
+ my ($param) = @_;
+
+ return call_api_method('PUSH', $param);
+ }});
+
+__PACKAGE__->register_method ({
+ name => 'pveclient_delete',
+ path => 'pveclient_delete',
+ method => 'DELETE',
+ description => "call API DELETE on <path>.",
+ parameters => {
+ additionalProperties => 0,
+ properties => $path_properties,
+ },
+ returns => $path_returns,
+ code => sub {
+ my ($param) = @_;
+
+ return call_api_method('DELETE', $param);
+ }});
+
+
+our $cmddef = {
+ config => $PVE::APIClient::Commands::config::cmddef,
+ list => $PVE::APIClient::Commands::list::cmddef,
+ lxc => $PVE::APIClient::Commands::lxc::cmddef,
+ remote => $PVE::APIClient::Commands::remote::cmddef,
+
+ spice => [ 'PVE::APIClient::Commands::GuestStatus', 'spice', ['remote', 'vmid']],
+ start => [ 'PVE::APIClient::Commands::GuestStatus', 'start', ['remote', 'vmid']],
+ stop => [ 'PVE::APIClient::Commands::GuestStatus', 'stop', ['remote', 'vmid']],
+
+ api => {
+ 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 ],
+ },
+};
+
+
+__PACKAGE__->run_cli_handler();