[siesta-commit] siesta/bin nacho,1.27,1.28

[prev] [thread] [next] [lurker] [Date index for 2002/09/16]

From: clampr
Subject: [siesta-commit] siesta/bin nacho,1.27,1.28
Date: 14:02 on 16 Sep 2002
Update of /cvsroot/siesta/siesta/bin
In directory usw-pr-cvs1:/tmp/cvs-serv25372

Modified Files:
	nacho 
Log Message:
make it a little more idiomatic


Index: nacho
===================================================================
RCS file: /cvsroot/siesta/siesta/bin/nacho,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- nacho	16 Sep 2002 10:47:28 -0000	1.27
+++ nacho	16 Sep 2002 13:01:58 -0000	1.28
@@ -1,11 +1,10 @@
 #!/usr/bin/perl -w
-
+# $Id$
 use strict;
 use Siesta;
 use Siesta::Config;
 use Siesta::List;
 use Siesta::User;
-use Data::Dumper;
 use POSIX qw/strftime/;
 
 # All possible modes that we can do
@@ -64,23 +63,23 @@
 exit 0;
 
 =head1 NAME
-  
+
 nacho - the siesta command line configuration tool
 
 =head1 DESCRIPTION
 
 Via nacho you can control pretty much every aspect of you Siesta system.
 
-This includes things like creating new lists, creating new users, adding 
-users to lists, setting up and configuring plugins for lists and, later, 
-probably handling administrative tasks. 
+This includes things like creating new lists, creating new users, adding
+users to lists, setting up and configuring plugins for lists and, later,
+probably handling administrative tasks.
 
 =head1 COMMANDS
 
-You can optionally pass a database to act on (the default is the 
-one defined in Siesta::Config). By doing 
+You can optionally pass a database to act on (the default is the
+one defined in Siesta::Config). By doing
 
-        -d [ database ] 
+        -d database
 
 The following commands are then valid
 
@@ -132,9 +131,9 @@
 
 }
 
-=head2 show-users-list [list-id]
+=head2 show-users-list I<list-id>
 
-show all the users of the list 'list-id'
+show all the users of the list I<list-id>
 
 =cut
 
@@ -152,9 +151,9 @@
 
 }
 
-=head2 show-lists-user [user-id]
+=head2 show-lists-user I<user-id>
 
-Show all the lists that the user 'user-id' is on.
+Show all the lists that the user I<user-id> is on.
 
 =cut
 
@@ -170,9 +169,9 @@
     }
 }
 
-=head2 new-user [email address/user id] [forename] [surname]
+=head2 new-user I<user_id> [ I<forename> I<surname>]
 
-Add a new user to the system. 
+Add a new user to the system.
 
 =cut
 
@@ -194,7 +193,7 @@
     print "User $forename $surname <$user_id> added\n";
 }
 
-=head2 show-user [user id]
+=head2 show-user I<user_id>
 
 Show the current set up of a user.
 
@@ -203,21 +202,20 @@
 sub show_user {
     my $user_id = shift || die "You must pass a user id\n";
 
-    my $user = Siesta::User->new($user_id) || die "Not a valid user id\n";
+    my $user = Siesta::User->new($user_id)
+      or die "Not a valid user id\n";
 
     foreach my $field (@Siesta::User::fields) {
         my $value = $user->$field() || '';
-
         printf "%s = %s\n", $field, $value;
     }
-
 }
 
-=head2 delete-user [email address/user id]
+=head2 delete-user I<user_id>
 
 Remove a user from the system.
 
-=cut 
+=cut
 
 sub delete_user {
     my $user_id = shift || die "You must pass a user id\n";
@@ -233,13 +231,13 @@
     print "User '$user_id' deleted\n";
 }
 
-=head2 modify-user [user id] [key] [value]
+=head2 modify-user I<user_id> I<key> I<value>
 
-Change a property of the user. See B<Siesta::User>
-for what propertys are valid.
+Change a property of the user. See B<Siesta::User> for what properties
+are valid.
 
-Note - you can effectively copy a user by setting the id. A new
-user with the new id will be created.
+Note - you can effectively copy a user by setting the id. A new user
+with the new id will be created.
 
 =cut
 
@@ -261,16 +259,16 @@
     print "Property '$key' set to '$value' for the user $user_id\n";
 }
 
-=head2 new-list [list id] [list owner] [post address] [return path]
+=head2 new-list I<list_id> I<list_owner> I<post_address> I<return_path>
 
-'list id' is the name of the list, 'list owner' is the administrator of the list,
-'post address' is the email address that users send mail to post to the list and 
-'return path' is  the address that bounces should come back to.
+I<list_id> is the name of the list, I<list_owner> is the administrator
+of the list, I<post_address> is the email address that users send mail
+to post to the list and I<return_path> is the address that bounces
+should come back to.
 
 =cut
 
 sub new_list {
-
     my $list_id     = shift || die "You must supply a list id\n";
     my $list_owner  = shift || die "You must supply a list owner\n";
     my $post_addr   = shift || die "You must supply a post address\n";
@@ -289,10 +287,9 @@
     print "Created the new list '$list_id' <$post_addr>\n";
     print "Paste this into your alias file to activate the list\n\n";
     create_alias($list_id);
-
 }
 
-=head2 delete-list [list id]
+=head2 delete-list I<list_id>
 
 Remove the list indicated from the system.
 
@@ -301,7 +298,8 @@
 sub delete_list {
     my $list_id = shift;
 
-    my $list = Siesta::List->new($list_id) || die "Not a valid list id\n";
+    my $list = Siesta::List->new($list_id)
+      or die "Not a valid list id\n";
 
     foreach my $user ( $list->members() ) {
         $list->remove_member($user);
@@ -312,54 +310,54 @@
     print "List '$list_id' deleted\n";
 }
 
-=head2 show-list [list id]
+=head2 show-list I<list_id>
 
-Show the current set up of a list.
+Show the current setup of a list.
 
 =cut
 
 sub show_list {
     my $list_id = shift || die "You must pass a list id\n";
 
-    my $list = Siesta::List->new($list_id) || die "Not a valid list id\n";
+    my $list = Siesta::List->new($list_id)
+      or die "Not a valid list id\n";
 
     foreach my $field (@Siesta::List::fields) {
         my $value = $list->$field() || '';
         printf "%s = %s\n", $field, $value;
     }
-
 }
 
-=head2 modify-list [list id] [key] [value]
+=head2 modify-list I<list_id> I<key> I<value>
 
-Change a property of the list specified. See B<Siesta::List> 
-for valid propertys.
+Change a property of the list specified.  See B<Siesta::List> for
+valid properties.
 
-Note: you can effectively copy the configuraion of a list by 
-modifying the id - a new list with the new id will be created 
-for you.
+Note: you can effectively copy the configuraion of a list by modifying
+the id - a new list with the new id will be created for you.
 
 =cut
 
 sub modify_list {
     my $list_id = shift || die "You must pass a user id\n";
 
-    my $list = Siesta::List->new($list_id) || die "Not a valid list id\n";
-
-    my %fields = map { $_ => 1 } @Siesta::List::fields;
+    my $list = Siesta::List->new($list_id)
+      or die "Not a valid list id\n";
 
     my ( $key, $value ) = @_;
 
-    die "'$key' is not a valid property\n" unless $fields{$key};
+    my %fields = map { $_ => 1 } @Siesta::List::fields;
+    die "'$key' is not a valid property\n"
+      unless $fields{$key};
 
     $list->$key($value);
-
-    $list->save() || die "Couldn't modify list $list_id\n";
+    $list->save()
+      or die "Couldn't modify list $list_id\n";
 
     print "Property '$key' set to '$value' for the list $list_id\n";
 }
 
-=head2 create-alias list_id
+=head2 create-alias I<list_id>
 
 Print out an alias file entry for the list specified.
 
@@ -388,78 +386,66 @@
 
 }
 
-=head2 add-user-list [list id] [user id(s)]
+=head2 add-user-list O<list_id> I<user> [I<user> ...]
 
-Add the users specified to the list specified. This will create 
-new users if necessary.
+Add the users specified to the list specified. This will create new
+users if necessary.
 
-=cut 
+=cut
 
 sub add_user_list {
-
     my $list_id = shift || die "You must pass a user id\n";
-
-    my $list = Siesta::List->new($list_id) || die "Not a valid list id\n";
-
     my $user_id = shift || die "You must pass a user id\n";
 
-    while ($user_id) {
+    my $list = Siesta::List->new($list_id)
+      or die "Not a valid list id\n";
 
-        # TODO - create new user if not valid
+    while ($user_id) {
         my $user = Siesta::User->new($user_id);
 
-        unless ( defined $user ) {
+        unless ( $user ) {
             $user = Siesta::User->new_from_hash( id => $user_id )
-              || die "Couldn't create a new user\n";
+              or die "Couldn't create a new user\n";
             $user->save();
-            print
-              "Created a new user '$user_id' - don't forget to set more details for them\n";
-
+            print "Created a new user '$user_id' - don't forget to set more details for them\n";
         }
 
         $list->add_member($user);
-
         print "User '$user_id' added to list '$list_id'\n";
-
         $user_id = shift;
     }
-
 }
 
-=head2 remove-user-list [list id] [user id(s)]
+=head2 remove-user-list I<list_id> I<user> [I<user>...]
 
-removes the specified user(s) from the list.
+removes the specified I<user>(s) from the list.
 
 =cut
 
 sub remove_user_list {
     my $list_id = shift || die "You must pass a user id\n";
-
-    my $list = Siesta::List->new($list_id) || die "Not a valid list id\n";
-
     my $user_id = shift || die "You must pass a user id\n";
 
-    while ($user_id) {
+    my $list = Siesta::List->new($list_id)
+      or die "Not a valid list id\n";
 
+    while ($user_id) {
         my $user = Siesta::User->new($user_id)
-          || die "$user_id is not a valid user id\n";
+          or die "$user_id is not a valid user id\n";
 
         $list->remove_member($user);
-
         print "User '$user_id' removed from list '$list_id'\n";
-
         $user_id = shift;
     }
 }
 
-=head2 show-all-plugins 
+=head2 show-all-plugins
 
-List all plugins in the system.
+List all plugins available to the system.
 
 =cut
 
 sub show_all_plugins {
-
     print "This system currently has these plugins installed : \n\n";
     foreach my $plugin ( Siesta->list_all_plugins() ) {
         my $class = "Siesta::Plugin::" . $plugin;
@@ -472,20 +458,20 @@
 
         print "$plugin -\n $description\n\n";
     }
-
 }
 
-=head2 show-plugins [list id]
+=head2 show-plugins I<list_id>
 
-List the plugins for the list specified in the order
-that they'll be executed.
+List the plugins for the list specified in the order that they'll be
+executed.
 
 =cut
 
 sub show_plugins {
     my $list_id = shift || die "You must pass a list id\n";
 
-    my $list = Siesta::List->new($list_id) || die "Not a valid list id\n";
+    my $list = Siesta::List->new($list_id)
+      or die "Not a valid list id\n";
 
     my $a = 1;
 
@@ -496,7 +482,7 @@
     }
 }
 
-=head2 set-plugins [ list id ] [ plugin id(s) ]
+=head2 set-plugins I<list_id> [ I<plugin> [ I<plugin>... ] ]
 
 Set the list plugins to be the ones specified in the order specified.
 
@@ -504,13 +490,13 @@
 
 sub set_plugins {
     my $list_id = shift || die "You must pass a list id\n";
-
-    my $list = Siesta::List->new($list_id) || die "Not a valid list id\n";
-
     my @plugins = @_;
 
+    my $list = Siesta::List->new($list_id)
+      or die "Not a valid list id\n";
+
     $list->set_plugins(@plugins)
-      || die "Sorry, couldn't do that for some reason\n";
+      or die "Sorry, couldn't do that for some reason\n";
 
     unless (@plugins) {
         print "Deleted plugins from $list_id\n";
@@ -526,7 +512,7 @@
 
 }
 
-=head2 add-plugin [ list id ] [ plugin id ] < position >
+=head2 add-plugin I<list_id> I<plugin> [ I<position> ]
 
 Add a plugin onto the end of a list or, if a position is supplied, 
 then insert it somewhere in that list. 1 is the first position.
@@ -535,23 +521,21 @@
 
 sub add_plugin {
     my $list_id = shift || die "You must pass a list id\n";
-
-    my $list = Siesta::List->new($list_id) || die "Not a valid list id\n";
-
     my $plugin = shift || die "You must pass a plugin id\n";
-
     my $position = shift;
 
+    my $list = Siesta::List->new($list_id)
+      or die "Not a valid list id\n";
+
     $list->add_plugin( $plugin, $position )
       or die "Sorry couldn't do that for some reason\n";
 
     print "Successfully added plugin in $plugin to $list_id";
     print " at position $position" if ( defined $position );
     print "\n";
-
 }
 
-=head2 show-plugin-options [plugin name]
+=head2 show-plugin-options I<plugin>
 
 List all the options for a particular plugin.
 
@@ -577,12 +561,11 @@
         print " - ", $option, " : ", $options->{$option}->{description}, "\n";
     }
     print "\n";
-
 }
 
-=head2 show-plugin-config-default [ plugin id ]
+=head2 show-plugin-config-default I<plugin>
 
-List the current default config options         
+List the current default config options
 
 =cut
 
@@ -596,32 +579,27 @@
     _list_plugin_config( $plugin_id, undef, undef );
 }
 
-=head2 set-plugin-config-default [ plugin id ] [ key ] [ value ]
+=head2 set-plugin-config-default I<plugin> I<key> I<value>
 
 Set the value of a config option for this plugin
 
-=cut 
+=cut
 
 sub set_plugin_config_default {
-
     my $plugin_id = shift || die "You must pass a plugin id\n";
+    my $key = shift || die "You must pass a config option\n";
+    my $value = shift || die "You must pass a new value\n";;
 
     my %plugins = map { $_ => 1 } Siesta->list_all_plugins;
 
     die "Not a valid plugin\n" unless $plugins{$plugin_id};
 
-    my $key = shift || die "You must pass a config option\n";
-
-    my $value = shift;
-
-    defined $value || die "You must pass a new value\n";
-
     _set_plugin_config( $plugin_id, undef, undef, $key, $value );
 }
 
-=head2 show-plugin-config-user [ plugin id ] [ user id ]
+=head2 show-plugin-config-user I<plugin> I<user_id>
 
-List the current per-user options for this user and this plugin 
+List the current per-user options for this user and this plugin
 
 =cut
 
@@ -637,15 +615,17 @@
     _list_plugin_config( $plugin_id, $user_id, undef );
 }
 
-=head2 set-plugin-config-user [ plugin id ] [ user id ] [ key ] [ value ]
+=head2 set-plugin-config-user I<plugin> I<user_id> I<key> I<value>
 
-Set the value of a config option for this user and this plugin 
+Set the value of a config option for this user and this plugin
 
 =cut
 
 sub set_plugin_config_user {
-
     my $plugin_id = shift || die "You must pass a plugin id\n";
+    my $key = shift || die "You must pass a config option\n";
+    my $value = shift;
+    defined $value || die "You must pass a new value\n";
 
     my %plugins = map { $_ => 1 } Siesta->list_all_plugins;
 
@@ -653,15 +633,10 @@
 
     my $user_id = shift || die "You must pass a user id\n";
 
-    my $key = shift || die "You must pass a config option\n";
-
-    my $value = shift;
-    defined $value || die "You must pass a new value\n";
-
     _set_plugin_config( $plugin_id, $user_id, undef, $key, $value );
 }
 
-=head2 show-plugin-config-list [ plugin id ] [ list id ]
+=head2 show-plugin-config-list I<plugin> I<list_id>
 
 List the current per-list options for this list and this plugin 
 
@@ -669,44 +644,39 @@
 
 sub show_plugin_config_list {
     my $plugin_id = shift || die "You must pass a plugin name\n";
+    my $list_id = shift || die "You must pass a list id\n";
 
     my %plugins = map { $_ => 1 } Siesta->list_all_plugins;
 
     die "Not a valid plugin\n" unless $plugins{$plugin_id};
 
-    my $list_id = shift || die "You must pass a list id\n";
-
     _list_plugin_config( $plugin_id, undef, $list_id );
 }
 
-=head2 set-plugin-config-list [ plugin id ] [ list id ] [ key ] [ value ]
+=head2 set-plugin-config-list I<plugin> I<list_id> I<key> I<value>
 
 Set the value of a config option for this list and this plugin
 
 =cut
 
 sub set_plugin_config_list {
-
     my $plugin_id = shift || die "You must pass a plugin id\n";
-
-    my %plugins = map { $_ => 1 } Siesta->list_all_plugins;
-
-    die "Not a valid plugin\n" unless $plugins{$plugin_id};
-
     my $list_id = shift || die "You must pass a list id\n";
-
     my $key = shift || die "You must pass a config option\n";
-
     my $value = shift;
-
     defined $value || die "You must pass a new value\n";
 
+    my %plugins = map { $_ => 1 } Siesta->list_all_plugins;
+
+    die "Not a valid plugin\n" unless $plugins{$plugin_id};
+
     _set_plugin_config( $plugin_id, undef, $list_id, $key, $value );
 }
 
-=head2 show-plugin-config-userlist [ plugin id ] [ user id ] [ list id ]
+=head2 show-plugin-config-userlist I<plugin> I<user_id> I<list_id>
 
-List the current per-user options for this user on this list and this plugin    
+List the current per-user options for this user on this list and this
+plugin
 
 =cut
 
@@ -723,29 +693,24 @@
     _list_plugin_config( $plugin_id, $user_id, $list_id );
 }
 
-=head2 set-plugin-config-userlist [ plugin id ] [ user id ] [ list id ] [ key ] [ value ]
+=head2 set-plugin-config-userlist I<plugin> I<user_id> I<list_id> I<key> I<value>
 
 Set the value of a config option for this user and list and this plugin
 
 =cut
 
 sub set_plugin_config_userlist {
-
     my $plugin_id = shift || die "You must pass a plugin id\n";
-
-    my %plugins = map { $_ => 1 } Siesta->list_all_plugins;
-
-    die "Not a valid plugin\n" unless $plugins{$plugin_id};
-
     my $user_id = shift || die "You must pass a user id\n";
-
     my $list_id = shift || die "You must pass a list id\n";
-
     my $key = shift || die "You must pass a config option\n";
-
     my $value = shift;
     defined $value || die "You must pass a new value\n";
 
+    my %plugins = map { $_ => 1 } Siesta->list_all_plugins;
+
+    die "Not a valid plugin\n" unless $plugins{$plugin_id};
+
     _set_plugin_config( $plugin_id, $user_id, $list_id, $key, $value );
 }
 
@@ -764,8 +729,8 @@
     $list_id ||= -1;
 
     # try and load the user and list
-    my $user = Siesta::User->new($user_id) || undef;
-    my $list = Siesta::List->new($list_id) || undef;
+    my $user = Siesta::User->new($user_id);
+    my $list = Siesta::List->new($list_id);
 
     # set up a message
     my $message = Siesta::Message->new();



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