]> git.proxmox.com Git - pve-client.git/blame - PVE/APIClient/Commands/help.pm
Add a simple implementation of list
[pve-client.git] / PVE / APIClient / Commands / help.pm
CommitLineData
63c02d8c
DM
1package PVE::APIClient::Commands::help;
2
3use strict;
4use warnings;
5
6use PVE::APIClient::Commands::help;
5b090843 7use PVE::APIClient::Commands::list;
63c02d8c
DM
8use PVE::APIClient::Commands::lxc;
9use PVE::APIClient::Commands::remote;
10
11use PVE::CLIHandler;
12
13use 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}};
aa9d64b3 49 $text .= $class->usage_str($name, "pveclient $subcommand $name", $arg_param, $fixed_param, $format, $class->can('read_password'));
63c02d8c
DM
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);
5b090843 59 $assemble_usage_string->('list', $PVE::APIClient::Commands::list::cmddef);
63c02d8c
DM
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
70our $cmddef = [ __PACKAGE__, 'help', []];
71
721;