Re: [patch] pg_test_timing does not prompt illegal option

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
Cc: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, "Zhang, Jie" <zhangjie2(at)cn(dot)fujitsu(dot)com>, "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [patch] pg_test_timing does not prompt illegal option
Date: 2019-04-17 16:36:31
Message-ID: 2671.1555518991@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr> writes:
>> I think it might be an actively bad idea. There's a pretty
>> widespread convention that "--" is a no-op switch indicating
>> the end of switches. At least some of our tools appear to
>> honor that behavior (probably because glibc's getopt_long
>> does; I do not think we are implementing it ourselves).

> "src/port/getopt_long.c" checks for "--" as the end of options.

Ah. But I was checking this on a Linux build that's using glibc's
implementation, not our own. It's pretty easy to prove that psql,
for one, acts that way when using the glibc subroutine:

$ psql -- -E
psql: error: could not connect to server: FATAL: database "-E" does not exist

We've generally felt that deferring to the behavior of the platform's
getopt() or getopt_long() is a better idea than trying to enforce some
lowest-common-denominator version of switch parsing, on the theory that
users of a given platform will be used to whatever its getopt does.
This does mean that we have undocumented behaviors on particular
platforms. I'd say that accepting "--" is one of them. Another example
is that glibc's getopt is willing to reorder the arguments, so that
for example this works for me:

$ psql template1 -E
psql (12devel)
Type "help" for help.

template1=# \set
...
ECHO_HIDDEN = 'on'
...

On other platforms that would not work, so we don't document it.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2019-04-17 17:43:25 Re: jsonpath
Previous Message Tom Lane 2019-04-17 16:20:29 Re: Unhappy about API changes in the no-fsm-for-small-rels patch