- my $res = call_method($path, $method, \@ARGV);
- die "implement me";
-} elsif ($cmd eq 'set') {
- die "implement me";
-} elsif ($cmd eq 'create') {
- die "implement me";
-} elsif ($cmd eq 'delete') {
- die "implement me";
-} elsif ($cmd eq 'lxc') {
- PVE::APIClient::Commands::lxc->run_cli_handler();
-} elsif ($cmd eq 'remote') {
- PVE::APIClient::Commands::remote->run_cli_handler();
-} elsif ($cmd eq 'bashcomplete') {
-
- my $cmdline = substr($ENV{COMP_LINE}, 0, $ENV{COMP_POINT});
- $cmdline =~ s/$cur$//;
-
- my ($bash_command, $cur, $prev) = @ARGV;
-
- my $args = [split(/\s+/, $cmdline)];
-
- if (scalar(@$args) == 1) {
- foreach my $p (qw(get set create delete lxc remote)) {
- print "$p\n" if $p =~ m/^$cur/;
+}
+
+$path_properties->{remote} = get_standard_option('pveclient-remote-name');
+$path_properties->{api_path} = $api_path_property;
+
+__PACKAGE__->register_method ({
+ name => 'pveclient_get',
+ path => 'pveclient_get',
+ method => 'GET',
+ description => "Call API GET on <api_path>.",
+ parameters => {
+ additionalProperties => 0,
+ properties => PVE::APIClient::RESTHandler::add_standard_output_properties($path_properties),
+ },
+ returns => { type => 'null' },
+ code => sub {
+ my ($param) = @_;
+
+ call_api_method('GET', $param);
+
+ return undef;
+ }});
+
+__PACKAGE__->register_method ({
+ name => 'pveclient_set',
+ path => 'pveclient_set',
+ method => 'PUT',
+ description => "Call API PUT on <api_path>.",
+ parameters => {
+ additionalProperties => 0,
+ properties => PVE::APIClient::RESTHandler::add_standard_output_properties($path_properties),
+ },
+ returns => { type => 'null' },
+ code => sub {
+ my ($param) = @_;
+
+ call_api_method('PUT', $param);
+
+ return undef;
+ }});
+
+__PACKAGE__->register_method ({
+ name => 'pveclient_create',
+ path => 'pveclient_create',
+ method => 'POST',
+ description => "Call API POST on <api_path>.",
+ parameters => {
+ additionalProperties => 0,
+ properties => PVE::APIClient::RESTHandler::add_standard_output_properties($path_properties),
+ },
+ returns => { type => 'null' },
+ code => sub {
+ my ($param) = @_;
+
+ call_api_method('PUSH', $param);
+
+ return undef;
+ }});
+
+__PACKAGE__->register_method ({
+ name => 'pveclient_delete',
+ path => 'pveclient_delete',
+ method => 'DELETE',
+ description => "Call API DELETE on <api_path>.",
+ parameters => {
+ additionalProperties => 0,
+ properties => PVE::APIClient::RESTHandler::add_standard_output_properties($path_properties),
+ },
+ returns => { type => 'null' },
+ code => sub {
+ my ($param) = @_;
+
+ call_api_method('DELETE', $param);
+
+ return undef;
+ }});
+
+__PACKAGE__->register_method ({
+ name => 'pveclient_usage',
+ path => 'pveclient_usage',
+ method => 'GET',
+ description => "print API usage information for <api_path>.",
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ api_path => $api_path_property,
+ verbose => {
+ description => "Verbose output format.",
+ type => 'boolean',
+ optional => 1,
+ },
+ returns => {
+ description => "Including schema for returned data.",
+ type => 'boolean',
+ optional => 1,
+ },
+ command => {
+ description => "API command.",
+ type => 'string',
+ enum => [ keys %$PVE::APIClient::Helpers::method_map ],
+ optional => 1,
+ },
+ },
+ },
+ returns => { type => 'null' },
+ code => sub {
+ my ($param) = @_;
+
+ my $path = $param->{api_path};
+
+ my $found = 0;
+ foreach my $cmd (qw(get set create delete)) {
+ next if $param->{command} && $cmd ne $param->{command};
+ my $method = $PVE::APIClient::Helpers::method_map->{$cmd};
+ my $uri_param = {};
+ my $info = PVE::APIClient::Helpers::find_method_info($path, $method, $uri_param, 1);
+ next if !$info;
+ $found = 1;
+
+ my $prefix = "pveclient api $cmd <remote> $path";
+ if ($param->{verbose}) {
+ print PVE::APIClient::RESTHandler::getopt_usage(
+ $info, $prefix, undef, $uri_param, 'full');
+
+ } else {
+ print "USAGE: " . PVE::APIClient::RESTHandler::getopt_usage(
+ $info, $prefix, undef, $uri_param, 'short');
+ }
+ if ($param-> {returns}) {
+ my $schema = to_json($info->{returns}, {utf8 => 1, canonical => 1, pretty => 1 });
+ print "RETURNS: $schema\n";
+ }