]> git.proxmox.com Git - pve-common.git/commitdiff
add helper for simple commands - handle_simple_cmd()
authorDietmar Maurer <dietmar@proxmox.com>
Wed, 12 Oct 2011 08:27:56 +0000 (10:27 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 12 Oct 2011 08:27:56 +0000 (10:27 +0200)
A simple command is a command without sub-command.

data/PVE/CLIHandler.pm

index 9725d75788629c7aded8982709ed7e6490160b6b..33011c691c17c23c4b96769c1ecb1c3905ef7d79 100644 (file)
@@ -187,9 +187,42 @@ sub handle_cmd {
 
     my $prefix = "$exename $cmd";
     my $res = $class->cli_handler($prefix, $name, \@ARGV, $arg_param, $uri_param, $pwcallback);
-    if ($outsub) {
-       &$outsub($res);
+
+    &$outsub($res) if $outsub;
+}
+
+sub handle_simple_cmd {
+    my ($def, $args, $pwcallback, $podfn) = @_;
+
+    my ($class, $name, $arg_param, $uri_param, $outsub) = @{$def};
+    die "no class specified" if !$class;
+
+    if (scalar(@$args) == 1) {
+       if ($args->[0] eq 'help') {
+           my $str = "USAGE: $name help\n";
+           $str .= $class->usage_str($name, $name, $arg_param, $uri_param, 'long');
+           print STDERR "$str\n\n";
+           return;
+       } elsif ($args->[0] eq 'verifyapi') {
+           PVE::RESTHandler::validate_method_schemas();
+           return;
+       } elsif ($args->[0] eq 'printmanpod') {
+           my $synopsis = " $name help\n\n";
+           my $str = $class->usage_str($name, $name, $arg_param, $uri_param, 'long');
+           $str =~ s/^USAGE://;
+           $str =~ s/\n/\n /g;
+           $synopsis .= $str;
+
+           my $parser = PVE::PodParser->new();
+           $parser->{include}->{synopsis} = $synopsis;
+           $parser->parse_from_file($podfn);
+           return;
+       }
     }
+
+    my $res = $class->cli_handler($name, $name, \@ARGV, $arg_param, $uri_param, $pwcallback);
+
+    &$outsub($res) if $outsub;
 }
 
 1;