Forráskód Böngészése

Add -v / --version option

Morten Brix Pedersen 24 éve
szülő
commit
5840ecec50
1 módosított fájl, 18 hozzáadás és 5 törlés
  1. 18 5
      pisg.pl

+ 18 - 5
pisg.pl

@@ -5,7 +5,7 @@ use Getopt::Long;
 
 
 # pisg - Perl IRC Statistics Generator
 # pisg - Perl IRC Statistics Generator
 #
 #
-# Copyright (C) 2001  <Morten Brix Pedersen> - morten@wtf.dk
+# Copyright (C) 2001-2002  <Morten Brix Pedersen> - morten@wtf.dk
 #
 #
 # This program is free software; you can redistribute it and/or modify
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # it under the terms of the GNU General Public License as published by
@@ -37,6 +37,12 @@ sub main
     my $cfg = get_cmdline_options($script_dir);
     my $cfg = get_cmdline_options($script_dir);
     push(@INC, $cfg->{modules_dir});
     push(@INC, $cfg->{modules_dir});
 
 
+    my $version;
+    if ($cfg->{version}) {
+        $version = 1;
+        undef $cfg->{version};
+    }
+
     my $pisg;
     my $pisg;
     eval <<END;
     eval <<END;
 
 
@@ -47,7 +53,12 @@ use Pisg;
     override_cfg => \$cfg,
     override_cfg => \$cfg,
     search_path => \$script_dir,
     search_path => \$script_dir,
 );
 );
-\$pisg->run();
+
+if (\$version) {
+    print \$pisg->{cfg}->{version} . "\n";
+} else {
+    \$pisg->run();
+}
 END
 END
     if ($@) {
     if ($@) {
         print $@;
         print $@;
@@ -71,7 +82,7 @@ sub get_cmdline_options
 
 
 my $usage = <<END_USAGE;
 my $usage = <<END_USAGE;
 Usage: pisg.pl [-ch channel] [-l logfile] [-o outputfile] [-ma maintainer]
 Usage: pisg.pl [-ch channel] [-l logfile] [-o outputfile] [-ma maintainer]
-[-f format] [-n network] [-d logdir] [-mo moduledir] [-s] [-h]
+[-f format] [-n network] [-d logdir] [-mo moduledir] [-s] [-v] [-h]
 
 
 -ch --channel=xxx      : Set channel name
 -ch --channel=xxx      : Set channel name
 -l  --logfile=xxx      : Log file to parse
 -l  --logfile=xxx      : Log file to parse
@@ -79,13 +90,14 @@ Usage: pisg.pl [-ch channel] [-l logfile] [-o outputfile] [-ma maintainer]
 -ma --maintainer=xxx   : Channel/statistics maintainer
 -ma --maintainer=xxx   : Channel/statistics maintainer
 -f  --format=xxx       : Logfile format [see FORMATS file]
 -f  --format=xxx       : Logfile format [see FORMATS file]
 -n  --network=xxx      : IRC network for the channel
 -n  --network=xxx      : IRC network for the channel
--d  --dir=xxx          : Analyze all files in this dir. Ignores logfile 
+-d  --dir=xxx          : Analyze all files in this dir. Ignores logfile
 -p  --prefix=xxx       : Analyse only files prefixed by xxx in dir
 -p  --prefix=xxx       : Analyse only files prefixed by xxx in dir
                          Only works with --dir
                          Only works with --dir
 -cf --cfg opt=value    : Specify configuration options, eg. -cf show_wpl=1
 -cf --cfg opt=value    : Specify configuration options, eg. -cf show_wpl=1
 -co --configfile=xxx   : Configuration file
 -co --configfile=xxx   : Configuration file
 -mo --moduledir=xxx    : Directory containing pisg modules
 -mo --moduledir=xxx    : Directory containing pisg modules
 -s  --silent           : Suppress output (except error messages)
 -s  --silent           : Suppress output (except error messages)
+-v  --version          : Show version
 -h  --help             : Output this message and exit.
 -h  --help             : Output this message and exit.
 
 
 Example:
 Example:
@@ -109,6 +121,7 @@ END_USAGE
                    'ignorefile=s' => \$tmp,
                    'ignorefile=s' => \$tmp,
                    'aliasfile=s'  => \$tmp,
                    'aliasfile=s'  => \$tmp,
                    'silent'       => \$silent,
                    'silent'       => \$silent,
+                   'version'      => \$cfg{version},
                    'cfg=s'        => \@cfg,
                    'cfg=s'        => \@cfg,
                    'help|?'       => \$help
                    'help|?'       => \$help
                ) == 0 or $help) {
                ) == 0 or $help) {
@@ -117,7 +130,7 @@ END_USAGE
 
 
     if ($tmp) {
     if ($tmp) {
         die("The aliasfile and ignorefile has been obsoleted by the new
         die("The aliasfile and ignorefile has been obsoleted by the new
-        pisg.cfg, please use that instead [look in pisg.cfg]\n");
+        pisg.cfg, please use that instead [see pisg.cfg]\n");
     }
     }
 
 
     if ($silent) { $cfg{silent} = 1; }
     if ($silent) { $cfg{silent} = 1; }