install -D -m 0644 PVE/APIClient/Config.pm ${LIB_DIR}/PVE/APIClient/Config.pm
install -D -m 0644 PVE/APIClient/Commands/remote.pm ${LIB_DIR}/PVE/APIClient/Commands/remote.pm
install -D -m 0644 PVE/APIClient/Commands/lxc.pm ${LIB_DIR}/PVE/APIClient/Commands/lxc.pm
+ install -D -m 0644 PVE/APIClient/Commands/help.pm ${LIB_DIR}/PVE/APIClient/Commands/help.pm
install -D -m 0644 pve-api-definition.js ${LIB_DIR}/pve-api-definition.js
install -D -m 0755 pveclient ${DESTDIR}/usr/bin/pveclient
install -D -m 0644 pveclient.bash-completion ${BASHCOMPLDIR}/pveclient
--- /dev/null
+package PVE::APIClient::Commands::help;
+
+use strict;
+use warnings;
+
+use PVE::APIClient::Commands::help;
+use PVE::APIClient::Commands::lxc;
+use PVE::APIClient::Commands::remote;
+
+use PVE::CLIHandler;
+
+use base qw(PVE::CLIHandler);
+
+__PACKAGE__->register_method ({
+ name => 'help',
+ path => 'help',
+ method => 'GET',
+ description => "Print usage information.",
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ verbose => {
+ description => "Verbose output - list all options.",
+ type => 'boolean',
+ optional => 1,
+ default => 0,
+ },
+ },
+ },
+ returns => { type => 'null'},
+ code => sub {
+ my ($param) = @_;
+
+ my $text = "USAGE: pveclient <cmd> ...\n\n" if !$param->{verbose};
+
+ my $format = $param->{verbose} ? 'full' : 'short';
+
+ my $assemble_usage_string = sub {
+ my ($subcommand, $def) = @_;
+
+ my $sortfunc = sub { sort keys %{$_[0]} };
+
+ if (ref($def) eq 'HASH') {
+ foreach my $cmd (&$sortfunc($def)) {
+
+ if (ref($def->{$cmd}) eq 'ARRAY') {
+ my ($class, $name, $arg_param, $fixed_param) = @{$def->{$cmd}};
+ $text .= $class->usage_str($name, "pveclient $subcommand $name", $arg_param, $fixed_param, $format);
+ }
+ }
+ } else {
+ my ($class, $name, $arg_param, $fixed_param) = @$def;
+ $text .= $class->usage_str($name, "pveclient $name", $arg_param, $fixed_param, $format);
+ }
+ };
+
+ $assemble_usage_string->('help', $PVE::APIClient::Commands::help::cmddef);
+ $assemble_usage_string->('lxc', $PVE::APIClient::Commands::lxc::cmddef);
+ $assemble_usage_string->('remote', $PVE::APIClient::Commands::remote::cmddef);
+
+ $text .= "pveclient <get/set/create/delete> <path> {options}\n\n";
+
+ print STDERR $text;
+
+ return undef;
+ }});
+
+our $cmddef = [ __PACKAGE__, 'help', []];
+
+1;
use PVE::APIClient::Helpers;
use PVE::APIClient::Commands::remote;
use PVE::APIClient::Commands::lxc;
+use PVE::APIClient::Commands::help;
use JSON;
-sub print_usage {
-
- my $text = "pveclient usage:\n\n";
-
- $text .= "pveclient remote <help|add|remove> {options}\n\n";
-
- $text .= "pveclient lxc <help|create|destroy|...> {options}\n\n";
-
- $text .= "pveclient <get/set/create/delete> <path> {options}\n\n";
-
- print STDERR $text;
-
-}
-
sub call_method {
my ($path, $method, $args) = @_;
my $cli_class_handlers = {
lxc => 'PVE::APIClient::Commands::lxc',
remote => 'PVE::APIClient::Commands::remote',
+ help => 'PVE::APIClient::Commands::help',
};
-my $cmd = shift || (print_usage() && exit(-1));
+my $cmd = shift;
+if (!defined($cmd)) {
+ PVE::APIClient::Commands::help->help({});
+ exit(-1);
+}
if ($cmd eq 'get') {
my $method = 'GET';
}
print join("\n", sort(keys %$packages)) . "\n";
} else {
- print_usage();
+ PVE::APIClient::Commands::help->help({});
}
exit(0);