diff --git a/lib/OptionParser.pm b/lib/OptionParser.pm index b1c2c699..2572ad23 100644 --- a/lib/OptionParser.pm +++ b/lib/OptionParser.pm @@ -838,7 +838,15 @@ sub _validate_type { } } my $defaults = $self->{DSNParser}->parse_options($self); - $opt->{value} = $self->{DSNParser}->parse($val, $prev, $defaults); + if (!$opt->{attributes}->{repeatable}) { + $opt->{value} = $self->{DSNParser}->parse($val, $prev, $defaults); + } else { + my $values = []; + for my $dsn_string (@$val) { + push @$values, $self->{DSNParser}->parse($dsn_string, $prev, $defaults); + } + $opt->{value} = $values; + } } elsif ( $val && $opt->{type} eq 'z' ) { # type size PTDEBUG && _d('Parsing option', $opt->{long}, 'as a size value'); diff --git a/t/lib/OptionParser.t b/t/lib/OptionParser.t index 7eeebd1f..717955f2 100644 --- a/t/lib/OptionParser.t +++ b/t/lib/OptionParser.t @@ -15,7 +15,7 @@ use OptionParser; use DSNParser; use PerconaTest; -use Test::More tests => 161; +use Test::More tests => 162; my $o = new OptionParser( description => 'OptionParser.t parses command line options.', usage => "$PROGRAM_NAME ", @@ -1736,7 +1736,7 @@ is_deeply( { A => undef, D => 'test', - F => undef, + F =>undef, P => '12346', S => undef, h => '127.1', @@ -1746,6 +1746,47 @@ is_deeply( 'Copies DSN values correctly (issue 460)' ); +# Test DSN can be repeatable +$o = new OptionParser( + description => 'OptionParser.t parses command line options.', + usage => "$PROGRAM_NAME " +); +# Hack DSNParser into OptionParser. This is just for testing. +$o->{DSNParser} = $dp; +$o->_parse_specs( + { spec => 'rep=d', desc => 'source', attributes => { repeatable => 1}, }, +); +@ARGV = ( + '--rep', 'h=127.1,P=12345,D=test,u=bob,p=foo', '--rep', 'h=127.1,P=12346', +); +$o->get_opts(); +my $ddest_dsn = $o->get('rep'); +is_deeply( + $ddest_dsn, + [ + { + A => undef, + u => 'bob', + D => 'test', + h => '127.1', + P => '12345', + S => undef, + p => 'foo', + F => undef + }, + { + p => undef, + F => undef, + u => undef, + D => undef, + A => undef, + P => '12346', + S => undef, + h => '127.1' + } + ], + 'DSN type can be repeatable' +); # ############################################################################# # Issue 248: Add --user, --pass, --host, etc to all tools # #############################################################################