chiark / gitweb /
Permit defvalopt $fn to be a scalar ref instead (nfc, since no users)
[dgit.git] / dgit
diff --git a/dgit b/dgit
index f068df6a50f267680368d2ffa5f72864c9644565..d4193ccd2e8d8df7da4d5c5460a57ea45176ca24 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -3111,19 +3111,22 @@ sub cmd_version {
 our (%valopts_long, %valopts_short);
 our @rvalopts;
 
-sub defvalopt ($$$&) {
-    my ($long,$short,$val_re,$fn) = @_;
-    my $oi = { Long => $long, Short => $short, Re => $val_re, Fn => $fn };
+sub defvalopt ($$$$) {
+    my ($long,$short,$val_re,$how) = @_;
+    my $oi = { Long => $long, Short => $short, Re => $val_re, How => $how };
     $valopts_long{$long} = $oi;
     $valopts_short{$short} = $oi;
-    # $fn subref should:
+    # $how subref should:
     #   do whatever assignemnt or thing it likes with $_[0]
     #   if the option should not be passed on to remote, @rvalopts=()
+    # or $how can be a scalar ref, meaning simply assign the value
 }
 
 defvalopt '--since-version', '-v', '[^_]+|_', sub {
     ($changes_since_version) = @_;
 };
+defvalopt '--distro', '-d', '.+', sub { ($idistro) = (@_); };
+defvalopt '--existing-package', '', '.*', sub { ($existing_package) = (@_); };
 
 sub parseopts () {
     my $om;
@@ -3146,7 +3149,12 @@ sub parseopts () {
        }
        badusage "bad value \`$val' for $what" unless
            $val =~ m/^$oi->{Re}$(?!\n)/s;
-       $oi->{Fn}($val);
+       my $how = $oi->{How};
+       if (ref($how) eq 'SCALAR') {
+           $$how = $val;
+       } else {
+           $how->($val);
+       }
        push @ropts, @rvalopts;
     };
 
@@ -3181,17 +3189,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;
@@ -3247,9 +3249,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;