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

svn-commits at proxmox.com svn-commits at proxmox.com
Wed Aug 25 15:37:21 CEST 2010


Author: dietmar
Date: 2010-08-25 13:37:21 +0000 (Wed, 25 Aug 2010)
New Revision: 5055

Modified:
   pve-common/trunk/CLIHandler.pm
   pve-common/trunk/RESTHandler.pm
Log:
bug fixes and some docu


Modified: pve-common/trunk/CLIHandler.pm
===================================================================
--- pve-common/trunk/CLIHandler.pm	2010-08-25 13:15:00 UTC (rev 5054)
+++ pve-common/trunk/CLIHandler.pm	2010-08-25 13:37:21 UTC (rev 5055)
@@ -9,6 +9,7 @@
 use base qw(PVE::RESTHandler);
 
 my $cmddef;
+my $exename;
 
 __PACKAGE__->register_method ({
     name => 'help', 
@@ -29,13 +30,15 @@
     code => sub {
 	my ($param) = @_;
 
+	die "not initialized" if !($cmddef && $exename);
+
 	my $cmd = $param->{cmd};
 
 	my ($class, $name, $arg_param, $uri_param) = @{$cmddef->{$cmd}};
 
 	raise_param_exc({ cmd => "no such command '$cmd'"}) if !$class;
 
-	my $str = $class->usage_str($name, "pvesm $cmd", $arg_param, $uri_param, 'full');
+	my $str = $class->usage_str($name, "$exename $cmd", $arg_param, $uri_param, 'full');
 	print $str;
 
 	return undef;
@@ -43,39 +46,42 @@
     }});
 
 sub print_usage_short {
-    my ($exename, $msg) = @_;
+    my ($msg) = @_;
 
+    die "not initialized" if !($cmddef && $exename);
+
     print STDERR "ERROR: $msg\n" if $msg;
-    print STDERR "USAGE: pvesm <COMMAND> [ARGS] [OPTIONS]\n";
+    print STDERR "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, "pvesm $cmd", $arg_param, $uri_param, 'short');
+	my $str = $class->usage_str($name, "$exename $cmd", $arg_param, $uri_param, 'short');
 	print STDERR "       $str";
     }
 }
 
 sub handle_cmd {
-    my ($def, $exename, $cmd, $args) = @_;
+    my ($def, $cmdname, $cmd, $args, $pwcallback) = @_;
 
     $cmddef = $def;
+    $exename = $cmdname;
 
     $cmddef->{help} = [ __PACKAGE__, 'help', ['cmd'] ];
 
     if (!$cmd) { 
-	print_usage_short ($exename, "no command specified");
+	print_usage_short ("no command specified");
 	exit (-1);
     }
 
     my ($class, $name, $arg_param, $uri_param, $outsub) = @{$cmddef->{$cmd}} if $cmddef->{$cmd};
 
     if (!$class) {
-	print_usage_short ($exename, "unknown command '$cmd'");
+	print_usage_short ("unknown command '$cmd'");
 	exit (-1);
     }
 
     my $prefix = "$exename $cmd";
-    my $res = $class->cli_handler2($prefix, $name, \@ARGV, $arg_param, $uri_param);
+    my $res = $class->cli_handler2($prefix, $name, \@ARGV, $arg_param, $uri_param, $pwcallback);
     if ($outsub) {
 	&$outsub($res);
     }

Modified: pve-common/trunk/RESTHandler.pm
===================================================================
--- pve-common/trunk/RESTHandler.pm	2010-08-25 13:15:00 UTC (rev 5054)
+++ pve-common/trunk/RESTHandler.pm	2010-08-25 13:37:21 UTC (rev 5055)
@@ -194,13 +194,20 @@
     return $result;
 }
 
+# generate usage information for command line tools
+#
+# $name        ... the name of the method
+# $prefix      ... usually something like "$exename $cmd" ('pvesm add')
+# $arg_param   ... list of parameters we want to get as ordered arguments on the command line
+# $fixed_param ... do not generate and info about those parameters
+# $format:
+#   'long'  ... default (list all options)
+#   'short' ... command line only (one line)
+#   'full'  ... also include description
+#
 sub usage_str {
     my ($self, $name, $prefix, $arg_param, $fixed_param, $format) = @_;
 
-    # format: 'long', 'short', 'full'
-    #' long'  ... default
-    # 'short' ... command line only (one line)
-    # 'full'  ... include description
 
     $format = 'long' if !$format;
 
@@ -301,6 +308,9 @@
 	$param->{$p} = $fixed_param->{$p};
     }
 
+    # after copy, we set $fixed_param->{password} to exclude password from usage info.
+    $fixed_param->{password} = 1 if $pwcallback;
+
     foreach my $p (@$arg_param) {
 	my $v = shift @$args;
 



More information about the pve-devel mailing list