[Bps-public-commit] r10209 - in RT-Client-Console: trunk/bin

dams at bestpractical.com dams at bestpractical.com
Sun Dec 30 18:28:01 EST 2007


Author: dams
Date: Sun Dec 30 18:28:00 2007
New Revision: 10209

Modified:
   RT-Client-Console/   (props changed)
   RT-Client-Console/trunk/bin/rtconsole

Log:
 r53 at pundit:  dams | 2007-12-30 23:27:23 +0000
 wrap the script in a main() function for testing purpose


Modified: RT-Client-Console/trunk/bin/rtconsole
==============================================================================
--- RT-Client-Console/trunk/bin/rtconsole	(original)
+++ RT-Client-Console/trunk/bin/rtconsole	Sun Dec 30 18:28:00 2007
@@ -10,90 +10,89 @@
 use Pod::Usage;
 use RT::Client::Console;
 
+main() unless caller;
 
-my %options;
-GetOptions(\%options,
-		   'server=s',
-		   'user=s',
-		   'pass=s',
-		   'config-file=s',
-		   'generate-config',
-		   'help',
-		   'debug'
-		  ) or usage();
-$options{help} and usage();
-
-sub usage {
-	pod2usage( {
-				-verbose => 1,
-			   }
-			 );
-}
-
-# Unless debug is set, we redirect STDERR => /dev/null
-if (!$options{debug}) {
-	close STDERR;
-	open STDERR, ">>/dev/null";
-}
-
-my $config = {};
-exists $options{$_} and $config->{connection}{$_} = $options{$_} foreach (qw(server user pass));
-
-my $config_filename = $ENV{HOME} . '/.rtconsolerc';
-exists $options{'config-file'} && length $options{'config-file'} and $config_filename = $options{'config-file'};
-
-my $config_ini;
-if ($options{'generate-config'}) {
-	if (! -e $config_filename) {
-		$config_ini = Config::Tiny->new() or
-		  die "Couldn't open $config_filename to save the configuration. The error was : $Config::Tiny::errstr \n";
-
-	} else {
-		$config_ini = Config::Tiny->read($config_filename) or
-		  die "Couldn't open $config_filename to save the configuration. The error was : $Config::Tiny::errstr \n";
-	}
-	$config_ini->{$_} = $config->{$_} foreach keys %$config;
-	$config_ini->write($config_filename) or
-		die "Couldn't open $config_filename to save the configuration. The error was : $Config::Tiny::errstr \n";
-	print "wrote configuration to file $config_filename\n";
-	exit;
+sub main {
+    my %options;
+    GetOptions(\%options,
+               'server=s',
+               'user=s',
+               'pass=s',
+               'config-file=s',
+               'generate-config',
+               'help',
+               'debug'
+              ) or usage();
+    $options{help} and usage();
+
+    # Unless debug is set, we redirect STDERR => /dev/null
+    if (!$options{debug}) {
+        close STDERR;
+        open STDERR, ">>/dev/null";
+    }
+
+    my $config = {};
+    exists $options{$_} and $config->{connection}{$_} = $options{$_} foreach (qw(server user pass));
+
+    my $config_filename = $ENV{HOME} . '/.rtconsolerc';
+    exists $options{'config-file'} && length $options{'config-file'} and $config_filename = $options{'config-file'};
+
+    my $config_ini;
+    if ($options{'generate-config'}) {
+        if (! -e $config_filename) {
+            $config_ini = Config::Tiny->new() or
+              die "Couldn't open $config_filename to save the configuration. The error was : $Config::Tiny::errstr \n";
+            
+        } else {
+            $config_ini = Config::Tiny->read($config_filename) or
+              die "Couldn't open $config_filename to save the configuration. The error was : $Config::Tiny::errstr \n";
+        }
+        $config_ini->{$_} = $config->{$_} foreach keys %$config;
+        $config_ini->write($config_filename) or
+          die "Couldn't open $config_filename to save the configuration. The error was : $Config::Tiny::errstr \n";
+        print "wrote configuration to file $config_filename\n";
+        return;
+    }
+    
+    if (-e $config_filename) {
+        $config_ini = Config::Tiny->read($config_filename) or
+          die "Couldn't open $config_filename to save the configuration. The error was : $Config::Tiny::errstr \n";
+        $config->{$_} = $config_ini->{$_} foreach keys %$config_ini;
+    }
+    
+    
+    my $curses_handler = new Curses;
+    noecho();
+    nodelay(1);
+    $curses_handler->keypad(1);
+    $curses_handler->syncok(1);
+    curs_set(0);
+    leaveok(1);
+    
+    # Erase the main window
+    
+    $curses_handler->erase();
+    
+    try {
+        RT::Client::Console->run(curses_handler => $curses_handler,
+                                 rt_servername => $config->{connection}{server},
+                                 rt_username => $config->{connection}{user},
+                                 rt_password => $config->{connection}{pass},
+                                );
+        endwin;
+    } otherwise {
+        endwin;
+        print STDERR "\n\n ---- Main Error Message :\n$@\n";
+    };
 }
 
-if (-e $config_filename) {
-	$config_ini = Config::Tiny->read($config_filename) or
-	  die "Couldn't open $config_filename to save the configuration. The error was : $Config::Tiny::errstr \n";
-	$config->{$_} = $config_ini->{$_} foreach keys %$config_ini;
+sub usage {
+    pod2usage( {
+                -verbose => 1,
+               }
+             );
 }
 
-
-my $curses_handler = new Curses;
-noecho();
-nodelay(1);
-$curses_handler->keypad(1);
-$curses_handler->syncok(1);
-curs_set(0);
-leaveok(1);
-
-# Erase the main window
-
-$curses_handler->erase();
-
-try {
-	RT::Client::Console->run(curses_handler => $curses_handler,
-							 rt_servername => $config->{connection}{server},
-							 rt_username => $config->{connection}{user},
-							 rt_password => $config->{connection}{pass},
-							);
-	endwin;
-} otherwise {
-	endwin;
-	print STDERR "\n\n ---- Main Error Message :\n$@\n";
-};
-
-
-
-exit(0);
-
 __END__
 
 =head1 NAME



More information about the Bps-public-commit mailing list