[pve-devel] r5109 - pve-common/trunk

svn-commits at proxmox.com svn-commits at proxmox.com
Fri Sep 10 12:14:18 CEST 2010


Author: dietmar
Date: 2010-09-10 10:14:18 +0000 (Fri, 10 Sep 2010)
New Revision: 5109

Modified:
   pve-common/trunk/CLIHandler.pm
   pve-common/trunk/ChangeLog
   pve-common/trunk/RESTHandler.pm
Log:
	* CLIHandler.pm: new verbose option for help.


Modified: pve-common/trunk/CLIHandler.pm
===================================================================
--- pve-common/trunk/CLIHandler.pm	2010-09-10 08:05:38 UTC (rev 5108)
+++ pve-common/trunk/CLIHandler.pm	2010-09-10 10:14:18 UTC (rev 5109)
@@ -15,7 +15,7 @@
     name => 'help', 
     path => 'help',
     method => 'GET',
-    description => "Get help about specified command",
+    description => "Get help about specified command.",
     parameters => {
     	additionalProperties => 0,
 	properties => {
@@ -24,6 +24,11 @@
 		type => 'string',
 		optional => 1,
 	    },
+	    verbose => {
+		description => "Verbose output format.",
+		type => 'boolean',
+		optional => 1,
+	    },
 	},
     },
     returns => { type => 'null' },
@@ -35,8 +40,15 @@
 
 	my $cmd = $param->{cmd};
 
+	my $verbose = defined($cmd) && $cmd; 
+	$verbose = $param->{verbose} if defined($param->{verbose});
+
 	if (!$cmd) {
-	    print_usage_short();
+	    if ($verbose) {
+		print_usage_verbose();
+	    } else {		
+		print_usage_short(\*STDOUT);
+	    }
 	    return undef;
 	}
 
@@ -44,25 +56,41 @@
 
 	raise_param_exc({ cmd => "no such command '$cmd'"}) if !$class;
 
-	my $str = $class->usage_str($name, "$exename $cmd", $arg_param, $uri_param, 'full');
-	print "$str\n";
+	my $str = $class->usage_str($name, "$exename $cmd", $arg_param, $uri_param, $verbose ? 'full' : 'short');
+	if ($verbose) {
+	    print "$str\n";
+	} else {
+	    print "USAGE: $str\n";
+	}
 
 	return undef;
 
     }});
 
+sub print_usage_verbose {
+
+    die "not initialized" if !($cmddef && $exename);
+
+    print "USAGE: $exename <COMMAND> [ARGS] [OPTIONS]\n\n";
+
+    foreach my $cmd (sort keys %$cmddef) {
+	my ($class, $name, $arg_param, $uri_param) = @{$cmddef->{$cmd}};
+	my $str = $class->usage_str($name, "$exename $cmd", $arg_param, $uri_param, 'full');
+	print "$str\n\n";
+    }
+}
 sub print_usage_short {
-    my ($msg) = @_;
+    my ($fd, $msg) = @_;
 
     die "not initialized" if !($cmddef && $exename);
 
-    print STDERR "ERROR: $msg\n" if $msg;
-    print STDERR "USAGE: $exename <COMMAND> [ARGS] [OPTIONS]\n";
+    print $fd "ERROR: $msg\n" if $msg;
+    print $fd "USAGE: $exename <COMMAND> [ARGS] [OPTIONS]\n";
 
     foreach my $cmd (sort keys %$cmddef) {
 	my ($class, $name, $arg_param, $uri_param) = @{$cmddef->{$cmd}};
 	my $str = $class->usage_str($name, "$exename $cmd", $arg_param, $uri_param, 'short');
-	print STDERR "       $str";
+	print $fd "       $str";
     }
 }
 
@@ -75,14 +103,14 @@
     $cmddef->{help} = [ __PACKAGE__, 'help', ['cmd'] ];
 
     if (!$cmd) { 
-	print_usage_short ("no command specified");
+	print_usage_short (\*STDERR, "no command specified");
 	exit (-1);
     }
 
     my ($class, $name, $arg_param, $uri_param, $outsub) = @{$cmddef->{$cmd}} if $cmddef->{$cmd};
 
     if (!$class) {
-	print_usage_short ("unknown command '$cmd'");
+	print_usage_short (\*STDERR, "unknown command '$cmd'");
 	exit (-1);
     }
 

Modified: pve-common/trunk/ChangeLog
===================================================================
--- pve-common/trunk/ChangeLog	2010-09-10 08:05:38 UTC (rev 5108)
+++ pve-common/trunk/ChangeLog	2010-09-10 10:14:18 UTC (rev 5109)
@@ -1,5 +1,7 @@
 2010-09-10  Proxmox Support Team  <support at proxmox.com>
 
+	* CLIHandler.pm: new verbose option for help.
+
 	* Tools.pm (kvmkeymaps): moved from PVE::Utils.
 
 	* JSONSchema.pm: add a new attribute caled 'typetext' (any better

Modified: pve-common/trunk/RESTHandler.pm
===================================================================
--- pve-common/trunk/RESTHandler.pm	2010-09-10 08:05:38 UTC (rev 5108)
+++ pve-common/trunk/RESTHandler.pm	2010-09-10 10:14:18 UTC (rev 5109)
@@ -328,7 +328,7 @@
 	}
     } 
 
-    $out .= "usage: " if $format ne 'short';
+    $out .= "USAGE: " if $format ne 'short';
 
     $out .= "$prefix $args";
 
@@ -336,13 +336,15 @@
 
     return $out if $format eq 'short';
 
+    if ($info->{description} && $format eq 'full') {
+	my $desc = Text::Wrap::wrap('  ', '  ', ($info->{description}));
+	$out .= "\n$desc\n\n";
+    }
+
     $out .= $argdescr if $argdescr;
 
     $out .= $opts if $opts;
 
-    if ($info->{description} && $format eq 'full') {
-	$out .= "\nDescription: $info->{description}\n";
-    }
     return $out;
 }
 




More information about the pve-devel mailing list