Re: Small TAP improvements

Поиск
Список
Период
Сортировка
От Michael Paquier
Тема Re: Small TAP improvements
Дата
Msg-id YqkYkP67FyWC+JYI@paquier.xyz
обсуждение исходный текст
Ответ на Re: Small TAP improvements  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: Small TAP improvements  (Andrew Dunstan <andrew@dunslane.net>)
Список pgsql-hackers
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.
--
Michael

Вложения

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

Предыдущее
От: Michael Paquier
Дата:
Сообщение: Re: Small TAP improvements
Следующее
От: Zheng Li
Дата:
Сообщение: Re: Support logical replication of DDLs