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