From: Ian Jackson Date: Fri, 14 Aug 2015 13:04:37 +0000 (+0100) Subject: Break out $valopt (nfc) X-Git-Tag: debian/1.2~16 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=dgit.git;a=commitdiff_plain;h=f83789bb6d8cda46a87a61ca846843376261ad35 Break out $valopt (nfc) --- diff --git a/dgit b/dgit index b3ddb548..f068df6a 100755 --- a/dgit +++ b/dgit @@ -3135,6 +3135,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/^-/; @@ -3204,17 +3218,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 \`$_'"; } @@ -3275,17 +3280,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 \`$_'";