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 '--since-version', '-v', '[^_]+|_', \$changes_since_version;
+defvalopt '--distro', '-d', '.+', \$idistro;
+defvalopt '', '-k', '.+', \$keyid;
+defvalopt '--existing-package','', '.*', \$existing_package;
+defvalopt '--build-products-dir','','.*', \$buildproductsdir;
+defvalopt '--clean', '', $cleanmode_re, \$cleanmode;
+defvalopt '--quilt', '', $quilt_modes_re, \$quilt_mode;
+
+defvalopt '', '-c', '.*=.*', sub { push @git, '-c', @_; };
+
+defvalopt '', '-C', '.+', sub {
+ ($changesfile) = (@_);
+ if ($changesfile =~ s#^(.*)/##) {
+ $buildproductsdir = $1;
+ }
+};
+
+defvalopt '--initiator-tempdir','','.*', sub {
+ ($initiator_tempdir) = (@_);
+ $initiator_tempdir =~ m#^/# or
+ badusage "--initiator-tempdir must be used specify an".
+ " absolute, not relative, directory."
};
sub parseopts () {
}
my $oi;
+ my $val;
+ my $valopt = sub {
+ my ($what) = @_;
+ @rvalopts = ($_);
+ if (!defined $val) {
+ badusage "$what needs a value" unless @ARGV;
+ $val = shift @ARGV;
+ push @rvalopts, $val;
+ }
+ badusage "bad value \`$val' for $what" unless
+ $val =~ m/^$oi->{Re}$(?!\n)/s;
+ my $how = $oi->{How};
+ if (ref($how) eq 'SCALAR') {
+ $$how = $val;
+ } else {
+ $how->($val);
+ }
+ push @ropts, @rvalopts;
+ };
while (@ARGV) {
last unless $ARGV[0] =~ m/^-/;
($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;
- } elsif (m/^--clean=($cleanmode_re)$/os) {
- push @ropts, $_;
- $cleanmode = $1;
- } elsif (m/^--clean=(.*)$/s) {
- badusage "unknown cleaning mode \`$1'";
- } elsif (m/^--quilt=($quilt_modes_re)$/s) {
- push @ropts, $_;
- $quilt_mode = $1;
- } elsif (m/^--quilt=(.*)$/s) {
- badusage "unknown quilt fixup mode \`$1'";
} elsif (m/^--ignore-dirty$/s) {
push @ropts, $_;
$ignoredirty = 1;
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 \`$_'";
}
push @ropts, $&;
push @changesopts, $_;
$_ = '';
- } 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;
- if ($changesfile =~ s#^(.*)/##) {
- $buildproductsdir = $1;
- }
- } elsif (s/^-k(.+)//s) {
- $keyid=$1;
- } elsif (m/^-[dCk]$/) {
- badusage
- "option \`$_' requires an argument (and no space before the argument)";
} elsif (s/^-wn$//s) {
push @ropts, $&;
$cleanmode = 'none';
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 \`$_'";