chiark / gitweb /
Use defvalopt scalar ref (no overall functional change)
[dgit.git] / dgit
diff --git a/dgit b/dgit
index 4f63f0324b56dea474fbd5beaab182feeb687b32..b9982bbbefb656f36a578595a3752cedd7145e09 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -3111,21 +3111,20 @@ 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) = (@_); };
+defvalopt '--since-version', '-v', '[^_]+|_', \$changes_since_version;
+defvalopt '--distro', '-d', '.+', \$idistro;
+defvalopt '--existing-package', '', '.*', \$existing_package;
 
 sub parseopts () {
     my $om;
@@ -3148,7 +3147,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;
     };