Add a simple implementation of list
[pve-client.git] / PVE / APIClient / Commands / help.pm
1 package PVE::APIClient::Commands::help;
2
3 use strict;
4 use warnings;
5
6 use PVE::APIClient::Commands::help;
7 use PVE::APIClient::Commands::list;
8 use PVE::APIClient::Commands::lxc;
9 use PVE::APIClient::Commands::remote;
10
11 use PVE::CLIHandler;
12
13 use base qw(PVE::CLIHandler);
14
15 __PACKAGE__->register_method ({
16     name => 'help',
17     path => 'help',
18     method => 'GET',
19     description => "Print usage information.",
20     parameters => {
21         additionalProperties => 0,
22         properties => {
23             verbose => {
24                 description => "Verbose output - list all options.",
25                 type => 'boolean',
26                 optional => 1,
27                 default => 0,
28             },
29         },
30     },
31     returns => { type => 'null'},
32     code => sub {
33         my ($param) = @_;
34
35         my $text = "USAGE: pveclient <cmd> ...\n\n" if !$param->{verbose};
36
37         my $format = $param->{verbose} ? 'full' : 'short';
38
39         my $assemble_usage_string = sub {
40             my ($subcommand, $def) = @_;
41
42             my $sortfunc = sub { sort keys %{$_[0]} };
43
44             if (ref($def) eq 'HASH') {
45                 foreach my $cmd (&$sortfunc($def)) {
46
47                     if (ref($def->{$cmd}) eq 'ARRAY') {
48                         my ($class, $name, $arg_param, $fixed_param) = @{$def->{$cmd}};
49                         $text .= $class->usage_str($name, "pveclient $subcommand $name", $arg_param, $fixed_param, $format, $class->can('read_password'));
50                     }
51                 }
52             } else {
53                 my ($class, $name, $arg_param, $fixed_param) = @$def;
54                 $text .= $class->usage_str($name, "pveclient $name", $arg_param, $fixed_param, $format);
55             }
56         };
57
58         $assemble_usage_string->('help', $PVE::APIClient::Commands::help::cmddef);
59         $assemble_usage_string->('list', $PVE::APIClient::Commands::list::cmddef);
60         $assemble_usage_string->('lxc', $PVE::APIClient::Commands::lxc::cmddef);
61         $assemble_usage_string->('remote', $PVE::APIClient::Commands::remote::cmddef);
62
63         $text .= "pveclient <get/set/create/delete> <path> {options}\n\n";
64
65         print STDERR $text;
66
67         return undef;
68     }});
69
70 our $cmddef = [ __PACKAGE__, 'help', []];
71
72 1;