]>
Commit | Line | Data |
---|---|---|
63c02d8c DM |
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}}; | |
aa9d64b3 | 48 | $text .= $class->usage_str($name, "pveclient $subcommand $name", $arg_param, $fixed_param, $format, $class->can('read_password')); |
63c02d8c DM |
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; |