cvs commit: p5ee/App-Options/lib/App Options.pm

[email protected] (Stephen Adkins)
Newsgroups perl.cvs.p5ee
Message-ID <[email protected]>
cvsuser     05/01/14 08:28:30

  Modified:    App-Options/lib/App Options.pm
  Log:
  version option cleaned up
  
  Revision  Changes    Path
  1.13      +68 -17    p5ee/App-Options/lib/App/Options.pm
  
  Index: Options.pm
  ===================================================================
  RCS file: /cvs/public/p5ee/App-Options/lib/App/Options.pm,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- Options.pm	14 Jan 2005 14:01:07 -0000	1.12
  +++ Options.pm	14 Jan 2005 16:28:29 -0000	1.13
  @@ -1,6 +1,6 @@
   
   #############################################################################
  -## $Id: Options.pm,v 1.12 2005/01/14 14:01:07 spadkins Exp $
  +## $Id: Options.pm,v 1.13 2005/01/14 16:28:29 spadkins Exp $
   #############################################################################
   
   package App::Options;
  @@ -395,6 +395,8 @@
       # Put the var/value pairs in %$values
       #################################################################
       my $debug_options = $values->{debug_options} || 0;
  +    my $show_help = 0;
  +    my $show_version = 0;
       if (! $init_args{no_cmd_args}) {
           while ($#ARGV >= 0 && $ARGV[0] =~ /^--?([^=-][^=]*)(=?)(.*)/) {
               $var = $1;
  @@ -405,6 +407,18 @@
           if ($#ARGV >= 0 && $ARGV[0] eq "--") {
               shift @ARGV;
           }
  +        if ($values->{help}) {
  +            $show_help = 1;
  +            delete $values->{help};
  +        }
  +        elsif ($values->{"?"}) {
  +            $show_help = 1;
  +            delete $values->{"?"};
  +        }
  +        elsif ($values->{version}) {
  +            $show_version = $values->{version};
  +            delete $values->{version};
  +        }
           $debug_options = $values->{debug_options} || 0;
           print STDERR "1. Parsed Command Line Options. [@options]\n" if ($debug_options);
       }
  @@ -878,8 +892,8 @@
       # 11. print version information (--version)
       #################################################################
   
  -    if ($values->{version}) {
  -        &print_version($prog_file, $values);
  +    if ($show_version) {
  +        &print_version($prog_file, $show_version, $values);
           exit(0);
       }
   
  @@ -888,7 +902,7 @@
       #################################################################
   
       my $exit_status = -1;
  -    if ($values->{"?"} || $values->{help}) {
  +    if ($show_help) {
           $exit_status = 0;
       }
   
  @@ -1032,7 +1046,7 @@
   }
   
   sub print_version {
  -    my ($prog_file, $values) = @_;
  +    my ($prog_file, $show_version, $values) = @_;
       print "Program: $prog_file\n";
       print "(use --version_packages to see version info for specific perl packages)\n";
       my ($module, $package, $version, $full_path);
  @@ -1082,7 +1096,7 @@
           $package =~ s/\.p[lm]$//;
           $package =~ s!/!::!g;
   
  -        if ($values->{version_packages} && $values->{version} eq "1") {
  +        if ($values->{version_packages} && $show_version ne "all") {
               $show_module = 0;
               foreach my $package_pattern (@package_pattern) {
                   if ($package =~ /$package_pattern/) {
  @@ -1469,22 +1483,59 @@
   
   =head2 Version
   
  -If the "--version" option is set on the command line,
  -the version information for the loaded modules is printed,
  -and the program is exited.
  +After all values have been parsed, various conditions are
  +checked to see if the program should print diagnostic information
  +rather than continue running.  Two of these examples are --version
  +and --help.
   
  -If additional modules should be loaded so that their version
  -number can be ascertained, use the --version_packages option.
  +If the "--version" option is set on the command line,
  +the version information for all loaded modules is printed,
  +and the program is exited.  (The version of a package/module is
  +assumed to be the value of the $VERSION variable in that package.
  +i.e. The version of the XYZ::Foo package is $XYZ::Foo::VERSION.)
   
      prog --version
  -   prog --version --version_packages=CGI
  -   prog --version --version_packages=CGI,Template
   
  -=head2 Help and Validations
  +Of course, this is all done implicitly in the BEGIN block (during
  +"use App::Options;").  If your program tried to set
  +$main::VERSION, it may not be set unless it is set explicitly
  +in the BEGIN block.
  +
  + #!/usr/bin/perl
  + BEGIN {
  +   $VERSION = "1.12";
  + }
  + use App::Options;
  +
  +This can be integrated with CVS file versioning using something 
  +like the following.
  +
  + #!/usr/bin/perl
  + BEGIN {
  +   $VERSION = do { my @r=(q$Revision: 1.13 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
  + }
  + use App::Options;
  +
  +Furthermore, the version information about some modules that you
  +might expect to have seen will not be printed because those modules
  +have not yet been loaded.  To fix this, use the --version_packages
  +option (or set it in an option file).  This option contains a
  +comma-separated list of modules and/or module regular expressions.
  +The modules are loaded, and the version information from all
  +resulting packages that match any of the patterns is printed.
  +
  + prog --version --version_packages=CGI
  + prog --version --version_packages=CGI,Template
  +
  +This also cuts down on the miscellaneous
  +modules (and pragmas) which might have cluttered up your view
  +of the version information you were interested in.
  +If you really wish to see version information for all
  +modules, use the --version=all option.
   
  -After all values have been parsed, various conditions are
  -checked to see if the program should not continue and the
  -usage statement be printed out.
  + prog --version=all --version_packages=CGI,Template
  +
  +=head2 Help and Validations
   
   If the "-?" or "--help" options were set on the command line,
   the usage statement is printed, and the program is exited.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.