Test and fix OptionParser so string opts don't consume the next opt if not string value is given.

This commit is contained in:
Daniel Nichter
2013-08-07 19:02:11 -07:00
parent 8a8cc3e8ce
commit ef4a56a8fe
2 changed files with 66 additions and 1 deletions

View File

@@ -554,12 +554,23 @@ sub _set_option {
my $long = exists $self->{opts}->{$opt} ? $opt
: exists $self->{short_opts}->{$opt} ? $self->{short_opts}->{$opt}
: die "Getopt::Long gave a nonexistent option: $opt";
# Reassign $opt.
$opt = $self->{opts}->{$long};
if ( $opt->{is_cumulative} ) {
$opt->{value}++;
}
elsif ( ($opt->{type} || '') eq 's' && $val =~ m/^--?(.+)/ ) {
# https://bugs.launchpad.net/percona-toolkit/+bug/1199589
my $next_opt = $1;
if ( exists $self->{opts}->{$next_opt}
|| exists $self->{short_opts}->{$next_opt} ) {
$self->save_error("--$long requires a string value");
return;
}
else {
$opt->{value} = $val;
}
}
else {
$opt->{value} = $val;
}