chiark / gitweb /
More general argument parsing; neaten code
authorMatthew Vernon <mcv21@cam.ac.uk>
Thu, 13 Feb 2014 18:16:39 +0000 (18:16 +0000)
committerMatthew Vernon <mcv21@cam.ac.uk>
Thu, 13 Feb 2014 18:16:39 +0000 (18:16 +0000)
Rather than special-casing -a, loop through any arguments (and
complain if there is anything other than -a).

Use .=

Use unless rather than if (!) ...

Signed-off-by: Matthew Vernon <matthewv@chiark.greenend.org.uk>
evade-mail-admin

index 6f3fe21f91d2ee279aa9ca4139ca1491200953b8..4e5be404f34b863de11d7ea24b49c2c70e7aaf54 100755 (executable)
@@ -409,20 +409,22 @@ sub listq ($) {
 }
 
 sub action_list {
-    my ($q, $listall);
-    if ($priv) { $listall = 1; }
-    if (@ARGV) {
-       my $v = shift @ARGV;
-       if ($v ne "-a") { 
-           die "only legal argument to list is -a";
-       } else { $listall=1; }
+    my $listall = 0;
+    $listall ||= $priv;
+    while (@ARGV) {
+       last unless $ARGV[0] =~ m/^-/;
+       $_ = shift @ARGV;
+       last if m/^--?$/;
+       if (m/^-a$/) {
+           $listall=1;
+       } else {
+           die "unknown option to list \`$_'\n";
+       }
     }
     nomoreargs;
-    $q="SELECT * FROM addrs WHERE user=?";
-    if (!$listall) {
-       $q = $q. " AND NOT redirect = ''";
-    }
-    $q = $q. " ORDER BY localpart";
+    my $q = "SELECT * FROM addrs WHERE user=?";
+    $q .= " AND NOT redirect = ''" unless $listall;
+    $q .= " ORDER BY localpart";
     $q = $dbh->prepare($q);
     $q->execute($user);
     listq($q);