chiark / gitweb /
Convert to defvalopt: --existing-package
[dgit.git] / dgit
diff --git a/dgit b/dgit
index b3ddb548357565e0c01ed5d8394ab3d976e8554e..4f63f0324b56dea474fbd5beaab182feeb687b32 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -3124,6 +3124,8 @@ sub defvalopt ($$$&) {
 defvalopt '--since-version', '-v', '[^_]+|_', sub {
     ($changes_since_version) = @_;
 };
+defvalopt '--distro', '-d', '.+', sub { ($idistro) = (@_); };
+defvalopt '--existing-package', '', '.*', sub { ($existing_package) = (@_); };
 
 sub parseopts () {
     my $om;
@@ -3135,6 +3137,20 @@ sub parseopts () {
     }
 
     my $oi;
+    my $val;
+    my $valopt = sub {
+       my ($what) = @_;
+       @rvalopts = ($_);
+       if (!defined $val) {
+           badusage "$what needs a value" unless length @ARGV;
+           $val = shift @ARGV;
+           push @rvalopts, $val;
+       }
+       badusage "bad value \`$val' for $what" unless
+           $val =~ m/^$oi->{Re}$(?!\n)/s;
+       $oi->{Fn}($val);
+       push @ropts, @rvalopts;
+    };
 
     while (@ARGV) {
        last unless $ARGV[0] =~ m/^-/;
@@ -3167,17 +3183,11 @@ sub parseopts () {
                     ($om = $opts_opt_map{$1})) {
                push @ropts, $_;
                push @$om, $2;
-           } elsif (m/^--existing-package=(.*)/s) {
-               push @ropts, $_;
-               $existing_package = $1;
            } elsif (m/^--initiator-tempdir=(.*)/s) {
                $initiator_tempdir = $1;
                $initiator_tempdir =~ m#^/# or
                    badusage "--initiator-tempdir must be used specify an".
                        " absolute, not relative, directory."
-           } elsif (m/^--distro=(.*)/s) {
-               push @ropts, $_;
-               $idistro = $1;
            } elsif (m/^--build-products-dir=(.*)/s) {
                push @ropts, $_;
                $buildproductsdir = $1;
@@ -3204,17 +3214,8 @@ sub parseopts () {
                push @ropts, $_;
                push @deliberatelies, $&;
            } elsif (m/^(--[-0-9a-z]+)(=|$)/ && ($oi = $valopts_long{$1})) {
-               @rvalopts = ($_);
-               my $val = $'; #';
-               if ($2 eq '') {
-                   badusage "$oi->{Long} needs a value" unless @ARGV;
-                   $val = shift @ARGV;
-                   push @rvalopts, $val;
-               }
-               badusage "bad value for $oi->{Long}" unless
-                   $val =~ m/^$oi->{Re}$(?!\n)/s;
-               $oi->{Fn}($val);
-               push @ropts, @rvalopts;
+               $val = $2 ? $' : undef; #';
+               $valopt->($oi->{Long});
            } else {
                badusage "unknown long option \`$_'";
            }
@@ -3242,9 +3243,6 @@ sub parseopts () {
                } elsif (s/^-c(.*=.*)//s) {
                    push @ropts, $&;
                    push @git, '-c', $1;
-               } elsif (s/^-d(.+)//s) {
-                   push @ropts, $&;
-                   $idistro = $1;
                } elsif (s/^-C(.+)//s) {
                    push @ropts, $&;
                    $changesfile = $1;
@@ -3275,17 +3273,9 @@ sub parseopts () {
                    push @ropts, $&;
                    $cleanmode = 'check';
                } elsif (m/^-[a-zA-Z]/ && ($oi = $valopts_short{$&})) {
-                   @rvalopts = ($_);
-                   my $val = $'; #';
-                   if (!length $val) {
-                       badusage "$oi->{Short} needs a value" unless @ARGV;
-                       $val = shift @ARGV;
-                       push @rvalopts, $val;
-                   }
-                   badusage "bad value for $oi->{Short}" unless
-                       $val =~ m/^$oi->{Re}$(?!\n)/s;
-                   $oi->{Fn}($val);
-                   push @ropts, @rvalopts;
+                   $val = $'; #';
+                   $val = undef unless length $val;
+                   $valopt->($oi->{Short});
                    $_ = '';
                } else {
                    badusage "unknown short option \`$_'";