[pve-devel] r6441 - in pve-common/trunk: . data data/PVE debian

svn-commits at proxmox.com svn-commits at proxmox.com
Wed Aug 10 10:19:40 CEST 2011


Author: dietmar
Date: 2011-08-10 10:19:39 +0200 (Wed, 10 Aug 2011)
New Revision: 6441

Modified:
   pve-common/trunk/Makefile
   pve-common/trunk/data/ChangeLog
   pve-common/trunk/data/PVE/CLIHandler.pm
   pve-common/trunk/debian/changelog
Log:
  * CLIHandler.pm: new command 'printmanpod' to generate manual pages.



Modified: pve-common/trunk/Makefile
===================================================================
--- pve-common/trunk/Makefile	2011-08-10 05:58:34 UTC (rev 6440)
+++ pve-common/trunk/Makefile	2011-08-10 08:19:39 UTC (rev 6441)
@@ -1,7 +1,7 @@
 RELEASE=2.0
 
 VERSION=1.0
-PKGREL=3
+PKGREL=4
 
 PACKAGE=libpve-common-perl
 

Modified: pve-common/trunk/data/ChangeLog
===================================================================
--- pve-common/trunk/data/ChangeLog	2011-08-10 05:58:34 UTC (rev 6440)
+++ pve-common/trunk/data/ChangeLog	2011-08-10 08:19:39 UTC (rev 6441)
@@ -1,3 +1,8 @@
+2011-08-10  Proxmox Support Team  <support at proxmox.com>
+
+	* PVE/CLIHandler.pm (print_pod_manpage): add method to generate
+	pod base manual pages (SYNOPSIS is auto generated).
+
 2011-08-05  Proxmox Support Team  <support at proxmox.com>
 
 	* PVE/CLIHandler.pm (help): avoid warning on undefined commands

Modified: pve-common/trunk/data/PVE/CLIHandler.pm
===================================================================
--- pve-common/trunk/data/PVE/CLIHandler.pm	2011-08-10 05:58:34 UTC (rev 6440)
+++ pve-common/trunk/data/PVE/CLIHandler.pm	2011-08-10 08:19:39 UTC (rev 6441)
@@ -1,3 +1,19 @@
+package PVE::PodParser;
+
+use Pod::Parser;
+
+ at ISA = qw(Pod::Parser);
+
+sub command { 
+    my ($self, $cmd, $text, $line_num, $pod_para)  = @_;
+
+    $self->textblock($pod_para->raw_text(), $line_num, $pod_para);
+
+    if ($cmd eq 'head1' && $text =~ m/^\s*SYNOPSIS\s/ && $self->{synopsis}) {
+	$self->textblock($self->{synopsis}, $line_num, $pod_para);
+    }
+}
+
 package PVE::CLIHandler;
 
 use strict;
@@ -11,6 +27,26 @@
 my $cmddef;
 my $exename;
 
+my $expand_command_name = sub {
+    my ($def, $cmd) = @_;
+
+    if (!$def->{$cmd}) {
+	my $expanded;
+	for my $k (keys(%$def)) {
+	    if ($k =~ m/^$cmd/) {
+		if ($expanded) {
+		    $expanded = undef; # more than one match
+		    last;
+		} else {
+		    $expanded = $k;
+		}
+	    }
+	}
+	$cmd = $expanded if $expanded;
+    }
+    return $cmd;
+};
+
 __PACKAGE__->register_method ({
     name => 'help', 
     path => 'help',
@@ -52,10 +88,13 @@
 	    return undef;
 	}
 
+	$cmd = &$expand_command_name($cmddef, $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, "$exename $cmd", $arg_param, $uri_param, $verbose ? 'full' : 'short');
 	if ($verbose) {
 	    print "$str\n";
@@ -67,6 +106,31 @@
 
     }});
 
+sub print_pod_manpage {
+    my ($podfn) = @_;
+
+    die "not initialized" if !($cmddef && $exename);
+    die "no pod filename" if !$podfn;
+
+    my $synopsis = "";
+    
+    $synopsis .= " $exename <COMMAND> [ARGS] [OPTIONS]\n\n";
+
+    my $oldclass;
+    foreach my $cmd (sorted_commands()) {
+	my ($class, $name, $arg_param, $uri_param) = @{$cmddef->{$cmd}};
+	my $str = $class->usage_str($name, "$exename $cmd", $arg_param, $uri_param, 'short');
+	$synopsis .= "\n" if $oldclass && $oldclass ne $class;
+	$synopsis .= " $str";
+	$oldclass = $class;
+    }
+
+    $synopsis .= "\n";
+
+    my $parser = PVE::PodParser->new(synopsis => $synopsis);
+    $parser->parse_from_file($podfn);
+}
+
 sub print_usage_verbose {
 
     die "not initialized" if !($cmddef && $exename);
@@ -103,7 +167,7 @@
 }
 
 sub handle_cmd {
-    my ($def, $cmdname, $cmd, $args, $pwcallback) = @_;
+    my ($def, $cmdname, $cmd, $args, $pwcallback, $podfn) = @_;
 
     $cmddef = $def;
     $exename = $cmdname;
@@ -113,24 +177,17 @@
     if (!$cmd) { 
 	print_usage_short (\*STDERR, "no command specified");
 	exit (-1);
+    } elsif ($cmd eq 'verifyapi') {
+	PVE::RESTHandler::validate_method_schemas();
+	return;
+    } elsif ($cmd eq 'printmanpod') {
+	print_pod_manpage($podfn);
+	return;
     }
 
-     if (!$cmddef->{$cmd}) {
-	my $expanded;
-	for my $k (keys(%$cmddef)) {
-	    if ($k =~ m/^$cmd/) {
-		if ($expanded) {
-		    $expanded = undef; # more than one match
-		    last;
-		} else {
-		    $expanded = $k;
-		}
-	    }
-	}
-	$cmd = $expanded if $expanded;
-     }
+    $cmd = &$expand_command_name($cmddef, $cmd);
 
-    my ($class, $name, $arg_param, $uri_param, $outsub) = @{$cmddef->{$cmd}} if $cmddef->{$cmd};
+    my ($class, $name, $arg_param, $uri_param, $outsub) = @{$cmddef->{$cmd} || []};
 
     if (!$class) {
 	print_usage_short (\*STDERR, "unknown command '$cmd'");

Modified: pve-common/trunk/debian/changelog
===================================================================
--- pve-common/trunk/debian/changelog	2011-08-10 05:58:34 UTC (rev 6440)
+++ pve-common/trunk/debian/changelog	2011-08-10 08:19:39 UTC (rev 6441)
@@ -1,3 +1,9 @@
+libpve-common-perl (1.0-4) unstable; urgency=low
+
+  * CLIHandler.pm: new command 'printmanpod' to generate manual pages.
+
+ -- Proxmox Support Team <support at proxmox.com>  Wed, 10 Aug 2011 10:17:55 +0200
+
 libpve-common-perl (1.0-3) unstable; urgency=low
 
   * fix CLIHandler.pm




More information about the pve-devel mailing list