https://www.mediawiki.org/wiki/Special:Code/MediaWiki/115408
Revision: 115408
Author: hashar
Date: 2012-05-21 15:17:18 +0000 (Mon, 21 May 2012)
Log Message:
-----------
handle command line argument + debug function
This is a very basic infrastructure to add up command line arguments to
wikibugs and some debugging message.
First feature is --stdout which let you print the message on STDOUT
instead of to the file.
Modified Paths:
--------------
trunk/tools/wikibugs/wikibugs
Modified: trunk/tools/wikibugs/wikibugs
===================================================================
--- trunk/tools/wikibugs/wikibugs 2012-05-21 15:17:11 UTC (rev 115407)
+++ trunk/tools/wikibugs/wikibugs 2012-05-21 15:17:18 UTC (rev 115408)
@@ -12,9 +12,38 @@
# http://wikitech.wikimedia.org/view/Wikibugs and finally migrated to
# the subversion repository in 2007.
+use warnings;
use strict;
use utf8;
+use Getopt::Long;
+use Pod::Usage;
+=head1 NAME
+wikibugs - A bugzilla IRC notification bot
+
+=head1 SYNOPSIS
+
+wikibugs [options]
+
+Options:
+
+ --help brief help message
+
+ --debug Write to STDERR some debugging messages
+
+ --stdout Write every message to stdout instead of files
+ usefull for debugging purposes.
+
+=cut
+
+# Array holding command line options
+my %opt = (
+ 'to' => '/var/wikibugs/wikibugs.log',
+ 'debug' => 0,
+);
+GetOptions( \%opt, 'debug', 'help', 'stdout' ) or pod2usage(2);
+pod2usage(1) if $opt{'help'};
+
$/ = undef;
my $contents = <STDIN>;
my $output;
@@ -172,8 +201,18 @@
$output = "$st $summary - \00310$url\003 " . $output;
if ($output) {
- open (OUT, ">>/var/wikibugs/wikibugs.log");
- #print $output;
- print OUT $output;
- close OUT;
+ if( $opt{'stdout'} ) {
+ print $output;
+ } else {
+ open (OUT, ">>/var/wikibugs/wikibugs.log");
+ print OUT $output;
+ close OUT;
+ }
}
+
+# Print a debugging message
+sub debug {
+ return unless $opt{'debug'};
+ my $message = shift;
+ print STDERR "Debug: $message\n";
+}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs