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