PT-115 Make DSNs params able to be repeatable

This commit is contained in:
Carlos Salguero
2017-03-30 10:10:54 -03:00
parent c554e98926
commit 1d4507537b
2 changed files with 52 additions and 3 deletions

View File

@@ -838,7 +838,15 @@ sub _validate_type {
}
}
my $defaults = $self->{DSNParser}->parse_options($self);
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');

View File

@@ -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 <options>",
@@ -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 <options>"
);
# 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
# #############################################################################