Re: Small TAP improvements

Поиск
Список
Период
Сортировка
От Andrew Dunstan
Тема Re: Small TAP improvements
Дата
Msg-id 193b30e3-49a8-185c-e39f-5d2d9e3fdbff@dunslane.net
обсуждение исходный текст
Ответ на Re: Small TAP improvements  (Michael Paquier <michael@paquier.xyz>)
Ответы Re: Small TAP improvements  (Michael Paquier <michael@paquier.xyz>)
Список pgsql-hackers
On 2022-06-14 Tu 19:24, Michael Paquier wrote:
> On Tue, Jun 14, 2022 at 05:08:28PM -0400, Tom Lane wrote:
>> Andrew Dunstan <andrew@dunslane.net> writes:
>>> OK, here's a more principled couple of patches. For config_data, if you
>>> give multiple options it gives you back the list of values. If you don't
>>> specify any, in scalar context it just gives you back all of pg_config's
>>> output, but in array context it gives you a map, so you should be able
>>> to say things like:
>>>     my %node_config = $node->config_data;
>> Might be overkill, but since you wrote it already, looks OK to me.
> +       # exactly one option: hand back the output (minus LF)
> +       return $stdout if (@options == 1);
> +       my @lines = split(/\n/, $stdout);
> +       # more than one option: hand back the list of values;
> +       return @lines if (@options);
> +       # no options, array context: return a map
> +       my @map;
> +       foreach my $line (@lines)
> +       {
> +               my ($k,$v) = split (/ = /,$line,2);
> +               push(@map, $k, $v);
> +       }
>
> This patch is able to handle the case of no option and one option
> specified by the caller of the routine.  However, pg_config is able to
> return a set of values when specifying multiple switches, respecting
> the order of the switches, so wouldn't it be better to return a map
> made of ($option, $line)?  For example, on a command like `pg_config
> --sysconfdir --`, we would get back:
> (('--sysconfdir', sysconfdir_val), ('--localedir', localedir_val))
>
> If this is not worth the trouble, I think that you'd better die() hard
> if the caller specifies more than two option switches.


My would we do that? If you want a map don't pass any switches. But as
written you could do:


my ($incdir, $localedir, $sharedir) = $node->config_data(qw(--includedir --localedir --sharedir));


No map needed to get what you want, in fact a map would get in the way.


cheers


andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com




В списке pgsql-hackers по дате отправления:

Предыдущее
От: "Daniel Verite"
Дата:
Сообщение: Re: Add header support to text format and matching feature
Следующее
От: Andrew Dunstan
Дата:
Сообщение: Re: Small TAP improvements