rev 1344 - trunk/siesta/bin

[prev] [thread] [next] [lurker] [Date index for 2003/08/13]

From: richardc
Subject: rev 1344 - trunk/siesta/bin
Date: 19:06 on 13 Aug 2003
Author: richardc
Date: 2003-08-13 19:06:37 +0100 (Wed, 13 Aug 2003)
New Revision: 1344

Modified:
   trunk/siesta/bin/nacho2
Log:
rip stuff up a bit


Modified: trunk/siesta/bin/nacho2
===================================================================
--- trunk/siesta/bin/nacho2	2003-08-13 16:10:52 UTC (rev 1343)
+++ trunk/siesta/bin/nacho2	2003-08-13 18:06:37 UTC (rev 1344)
@@ -7,24 +7,23 @@
 use String::ShellQuote;
 use UNIVERSAL::require;
 use Pod::Usage;
-use Getopt::ArgvFile qw(argvFile);
 use Getopt::Long;
+use Siesta::Config;
 
 use vars qw/ $VERSION %COMMANDS /;
 $VERSION = "1.1";
 
-
 =head1 NAME
 
 nacho-ex - the siesta command line configuration tool
 
 =head1 SYNOPSIS
 
-nacho-ex [command [options]...]
+ nacho-ex [ global options ] [command [options]...]
 
- Generic Options:
-   -d, --database=DBI_URI  \ these two options allow you to override
-   -f, --config-file=FILE  / the values defined in Siesta::Config
+ Global Options:
+   -d, --database=DBI_DSN
+   -f, --config-file=FILE
 
    -h, --help           help text detailing the commands and their options
    -V, --version        prints the version number
@@ -38,10 +37,9 @@
                   modify-member    delete-member
  Plugin Commands: show-plugins     describe-plugins  modify-plugin
 
- Options and commands may be read from a file by giving the name of the
- file prefixed by a @. The database and config-file options affect all
- of the supplied commands. if either of them is supplied more than once,
- the last one will take priority.
+The database and config-file options affect all of the supplied
+commands. if either of them is supplied more than once, the last one
+will take priority.
 
 =head1 OPTIONS
 
@@ -141,12 +139,12 @@
     # think.  I'm not terribly keen, it make everything even uglier
     # than before --richardc
 
-    $COMMANDS{'create-database'}  = {
-            action => sub {
-                require Siesta::DBI;
-                Siesta::DBI->init_db;
-            },
-        };
+    $COMMANDS{'create-database'} = {
+        action => sub {
+            require Siesta::DBI;
+            Siesta::DBI->init_db;
+        },
+    };
 
     $COMMANDS{'run-mariachi'} = {
         action => sub {
@@ -157,8 +155,9 @@
                 my $output = $Siesta::Config::ROOT . "/mariachi-html/$name";
                 print "invoking mariachi for $name\n";
                 system 'mariachi', '-i', $input, '-o', $output, '-n', $name;
-            },
-        };
+            }
+        },
+    };
 
     $COMMANDS{'create-backup'} = {
         optional => [qw/ list=s /],
@@ -544,7 +543,6 @@
         }
        };
 
-    argvFile;
 }
 
 sub _plugin_options {
@@ -609,31 +607,32 @@
 #
 #####
 
+use Getopt::Auto map { [ $_, '', sub { run($_) } ] } keys %COMMANDS;
 
-use Getopt::Auto (
-    map { my $name = $_; [ $name, '', sub { run($name) } ] }
-      keys %COMMANDS
-     );
-
 BEGIN {
-    no warnings;
-    *Getopt::Auto::helpme = \&helpme;
-    *Getopt::Auto::unrecognized = \&unrecognized;
-}
+    {
+        no warnings;
+        *Getopt::Auto::helpme = \&helpme;
+        *Getopt::Auto::unrecognized = \&unrecognized;
+    }
 
-use Siesta::Config;
-BEGIN {
     my $database;
     my $config;
 
-    Getopt::Long::Configure ("pass_through");
-    GetOptions('database=s' => \$database,
+    Getopt::Long::Configure("pass_through", "require_order");
+    GetOptions('database=s'      => \$database,
                'config-file|f=s' => \$config);
 
+    # XXX what if they said -f -d?
     @Siesta::Config::STORAGE = split / /, $database if defined $database;
-    $Siesta::Config::CONFIG_FILE = $config if defined $config;
+    Siesta::Config->load_from( $config ) if defined $config;
 }
 
+
+# Getopt::Auto does all its funning in an INIT block
+
+exit 0;
+
 sub run {
     my $command = shift;
 
@@ -649,13 +648,13 @@
         }
     }
 
-    my %h = ();
+    my %h;
     my @options = grep { defined } (
         @{$COMMANDS{$command}{required}},
         @{$COMMANDS{$command}{optional}}
        );
 
-    Getopt::Long::Configure ("no_pass_through", "require_order");
+    Getopt::Long::Configure( "no_pass_through", "require_order" );
     GetOptions(\%h, @options) or exit(2);
 
     my @missing;
@@ -667,24 +666,23 @@
     while (my ($key, $value) = each %{$COMMANDS{$command}{dependencies}} ) {
         push @missing, $value if defined $h{$key} and !defined $h{$value};
     }
-    if (scalar @missing) {
+    if (@missing) {
         local $" = ", ";
         print "The following options to the command $command are missing:\n";
         print "    " . "@missing\n";
         exit(2);
     }
 
-    eval { $COMMANDS{$command}{action}->(%h); };
+    eval { $COMMANDS{$command}{action}->(%h) };
     if ($@) {
         print $@;
         return 0;
     }
 
-    if (scalar @ARGV != 0) {
+    if (@ARGV) {
         print "#################\n";
         print "## end of command\n";
         print "#################\n";
-
         return 1;
     }
     else {
@@ -705,7 +703,6 @@
 #
 #####
 
-
 sub helpme {
     my $verbosity = shift;
 

Generated at 13:57 on 01 Jul 2004 by mariachi 0.52