X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=dgit.git;a=blobdiff_plain;f=dgit;h=89633444a5979c570bd0b4bf2514bd7e33f2d313;hp=83969717816bc5286d0566d2d7f1956e1085ad05;hb=bf5e40c8a56c5d7c3f78b50d354bd6568190375a;hpb=d4bd3417c76450f248952606bff7e586600e34a8 diff --git a/dgit b/dgit index 83969717..89633444 100755 --- a/dgit +++ b/dgit @@ -3108,6 +3108,24 @@ sub cmd_version { exit 0; } +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 }; + $valopts_long{$long} = $oi; + $valopts_short{$short} = $oi; + # $fn subref should: + # do whatever assignemnt or thing it likes with $_[0] + # if the option should not be passed on to remote, @rvalopts=() +} + +defvalopt '--since-version', '-v', '[^_]+|_', sub { + ($changes_since_version) = @_; +}; +defvalopt '--distro', '-d', '.+', sub { ($idistro) = (@_); }; + sub parseopts () { my $om; @@ -3117,6 +3135,22 @@ sub parseopts () { @ssh = ($ENV{'GIT_SSH'}); } + 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/^-/; $_ = shift @ARGV; @@ -3138,9 +3172,6 @@ sub parseopts () { } elsif (m/^--new$/) { push @ropts, $_; $new_package=1; - } elsif (m/^--since-version=([^_]+|_)$/) { - push @ropts, $_; - $changes_since_version = $1; } elsif (m/^--([-0-9a-z]+)=(.+)/s && ($om = $opts_opt_map{$1}) && length $om->[0]) { @@ -3159,9 +3190,6 @@ sub parseopts () { $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; @@ -3187,6 +3215,9 @@ sub parseopts () { } elsif (m/^--deliberately-($deliberately_re)$/s) { push @ropts, $_; push @deliberatelies, $&; + } elsif (m/^(--[-0-9a-z]+)(=|$)/ && ($oi = $valopts_long{$1})) { + $val = $2 ? $' : undef; #'; + $valopt->($oi->{Long}); } else { badusage "unknown long option \`$_'"; } @@ -3207,9 +3238,6 @@ sub parseopts () { } elsif (s/^-N/-/) { push @ropts, $&; $new_package=1; - } elsif (s/^-v([^_]+|_)$//s) { - push @ropts, $&; - $changes_since_version = $1; } elsif (m/^-m/) { push @ropts, $&; push @changesopts, $_; @@ -3217,9 +3245,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; @@ -3228,7 +3253,7 @@ sub parseopts () { } } elsif (s/^-k(.+)//s) { $keyid=$1; - } elsif (m/^-[vdCk]$/) { + } elsif (m/^-[dCk]$/) { badusage "option \`$_' requires an argument (and no space before the argument)"; } elsif (s/^-wn$//s) { @@ -3249,6 +3274,11 @@ sub parseopts () { } elsif (s/^-wc$//s) { push @ropts, $&; $cleanmode = 'check'; + } elsif (m/^-[a-zA-Z]/ && ($oi = $valopts_short{$&})) { + $val = $'; #'; + $val = undef unless length $val; + $valopt->($oi->{Short}); + $_ = ''; } else { badusage "unknown short option \`$_'"; }