Обсуждение: BUG #19042: Option --help not recognized at the end of command line in pg_restore

Поиск
Список
Период
Сортировка

BUG #19042: Option --help not recognized at the end of command line in pg_restore

От
PG Bug reporting form
Дата:
The following bug has been logged on the website:

Bug reference:      19042
Logged by:          Matthias Hörmann
Email address:      matthias.hoermann@saltation.com
PostgreSQL version: 17.6
Operating system:   Debian bookworm
Description:

When calling pg_restore trying to use --help at the end to see which other
options I might want to specify tells me that --help is an unrecognized
option and I am supposed to run pg_restore --help for more information.

```
# pg_restore --version
pg_restore (PostgreSQL) 17.6 (Debian 17.6-1.pgdg12+1)
# sudo -u postgres pg_restore -f /tmp/redacted_20250903_130108.pg_dump
--help
/usr/lib/postgresql/17/bin/pg_restore: unrecognized option '--help'
pg_restore: hint: Try "pg_restore --help" for more information.
```


Re: BUG #19042: Option --help not recognized at the end of command line in pg_restore

От
Daniel Gustafsson
Дата:
> On 3 Sep 2025, at 13:07, PG Bug reporting form <noreply@postgresql.org> wrote:

> When calling pg_restore trying to use --help at the end to see which other
> options I might want to specify tells me that --help is an unrecognized
> option and I am supposed to run pg_restore --help for more information.

This is the intended behaviour, --help (and --version) is parsed specially and
must be the first parameter. We do this for all command line utilities.

--
Daniel Gustafsson




Re: BUG #19042: Option --help not recognized at the end of command line in pg_restore

От
Matthias Hörmann
Дата:
The 2025-09-03 13:45:15, Daniel Gustafsson wrote:
> > On 3 Sep 2025, at 13:07, PG Bug reporting form <noreply@postgresql.org> wrote:
> 
> > When calling pg_restore trying to use --help at the end to see which other
> > options I might want to specify tells me that --help is an unrecognized
> > option and I am supposed to run pg_restore --help for more information.
> 
> This is the intended behaviour, --help (and --version) is parsed specially and
> must be the first parameter. We do this for all command line utilities.
> 
> --
> Daniel Gustafsson
> 

Well, the use-case that comes up quite often for me (for any commands,
not just postgres) is that I add parameters I know or remember from my
last look at --help and then want to check again what else to add, for
that it is useful to be able to use --help as the last parameter.

-- 
Mit freundlichen Grüßen,

Matthias Hörmann

fon: +49 (0) 521 - 329647-29
fax: +49 (0) 521 - 329647-40
email: matthias.hoermann@saltation.com

---------------
saltation GmbH & Co. KG | Stapenhorststraße 42b | 33615 Bielefeld
Sitz Bielefeld | Amtsgericht Bielefeld HRA 15344
Persönlich haftende Gesellschafterin:
saltation Beteiligungs-GmbH | Stapenhorststraße 42b | 33615 Bielefeld
Sitz Bielefeld | Amtsgericht Bielefeld HRB 39339
Geschäftsführer: Daniel Brün
---------------

Wir erfüllen unsere Informationspflichten gem. Artt. 13-14 DS-GVO
durch Veröffentlichung auf unserer Internetseite unter

https://www.saltation.com/de/datenschutzerklaerung.html

oder durch Zusendung auf Ihre formlose Anfrage.



Matthias =?utf-8?Q?H=C3=B6rmann?= <matthias.hoermann@saltation.com> writes:
> The 2025-09-03 13:45:15, Daniel Gustafsson wrote:
>> This is the intended behaviour, --help (and --version) is parsed specially and
>> must be the first parameter. We do this for all command line utilities.

> Well, the use-case that comes up quite often for me (for any commands,
> not just postgres) is that I add parameters I know or remember from my
> last look at --help and then want to check again what else to add, for
> that it is useful to be able to use --help as the last parameter.

FWIW, I agree with this.  While I don't try to do that with PG
utilities (since I know it doesn't work), I frequently rely on that
behavior of our configure script.  I'd be in favor of recognizing
--help (though probably not -?) in any argument position.  Less sure
about --version.

            regards, tom lane



Re: BUG #19042: Option --help not recognized at the end of command line in pg_restore

От
Daniel Gustafsson
Дата:
> On 3 Sep 2025, at 16:57, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> Matthias =?utf-8?Q?H=C3=B6rmann?= <matthias.hoermann@saltation.com> writes:
>> The 2025-09-03 13:45:15, Daniel Gustafsson wrote:
>>> This is the intended behaviour, --help (and --version) is parsed specially and
>>> must be the first parameter. We do this for all command line utilities.
>
>> Well, the use-case that comes up quite often for me (for any commands,
>> not just postgres) is that I add parameters I know or remember from my
>> last look at --help and then want to check again what else to add, for
>> that it is useful to be able to use --help as the last parameter.
>
> FWIW, I agree with this.

Same here, it's a totally reasonable ask.

> I'd be in favor of recognizing
> --help (though probably not -?) in any argument position.

Any particular reason to restrict -? from this?

> Less sure about --version.

Agreed, I think --version should require being the sole parameter.

--
Daniel Gustafsson




Daniel Gustafsson <daniel@yesql.se> writes:
> On 3 Sep 2025, at 16:57, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> I'd be in favor of recognizing
>> --help (though probably not -?) in any argument position.  

> Any particular reason to restrict -? from this?

I'm not set on that either way.  It just seems like --help is
quite unambiguous and unlikely to be a typo, whereas I'm less
sure about -?.  I won't stand in the way of a consensus to
do this for both.

            regards, tom lane



Re: BUG #19042: Option --help not recognized at the end of command line in pg_restore

От
Andres Freund
Дата:
Hi,

On 2025-09-03 10:57:53 -0400, Tom Lane wrote:
> Matthias =?utf-8?Q?H=C3=B6rmann?= <matthias.hoermann@saltation.com> writes:
> > The 2025-09-03 13:45:15, Daniel Gustafsson wrote:
> >> This is the intended behaviour, --help (and --version) is parsed specially and
> >> must be the first parameter. We do this for all command line utilities.
>
> > Well, the use-case that comes up quite often for me (for any commands,
> > not just postgres) is that I add parameters I know or remember from my
> > last look at --help and then want to check again what else to add, for
> > that it is useful to be able to use --help as the last parameter.
>
> FWIW, I agree with this.  While I don't try to do that with PG
> utilities (since I know it doesn't work), I frequently rely on that
> behavior of our configure script.  I'd be in favor of recognizing
> --help (though probably not -?) in any argument position.  Less sure
> about --version.

I've been annoyed by this behaviour for a long time.

So +many for recognizing --help (and I'd say -?) everywhere, not just as the
first argument. I never understood why we don't do that.

I don't think the argument for --version is particularly strong from a
usability perspective, but I don't see what we gain from parsing --version/-V
differently than we do all the other arguments. It seems best to just handle
--version the same as all the other arguments.

Greetings,

Andres



Re: BUG #19042: Option --help not recognized at the end of command line in pg_restore

От
Greg Sabino Mullane
Дата:
On Wed, Sep 3, 2025 at 7:48 AM Matthias Hörmann <matthias.hoermann@saltation.com> wrote:
Well, the use-case that comes up quite often for me (for any commands,
not just postgres) is that I add parameters I know or remember from my
last look at --help and then want to check again what else to add, for
that it is useful to be able to use --help as the last parameter.

Heavy +1 to fix this - it's always been a pet peeve of mine. Postgres tools are not the only ones that do this, but they are definitely an outlier.
 
Cheers,
Greg

--
Enterprise Postgres Software Products & Tech Support

Re: BUG #19042: Option --help not recognized at the end of command line in pg_restore

От
Peter Eisentraut
Дата:
On 03.09.25 21:34, Andres Freund wrote:
> So +many for recognizing --help (and I'd say -?) everywhere, not just as the
> first argument. I never understood why we don't do that.

I think in the olden days we didn't have universal getopt_long() 
support, so it was hardcoded.  I don't see a problem with changing it.

> I don't think the argument for --version is particularly strong from a
> usability perspective, but I don't see what we gain from parsing --version/-V
> differently than we do all the other arguments. It seems best to just handle
> --version the same as all the other arguments.

Right.  If you try the usual GNU utilities, they handle --help and
--version at any argument position.




Re: BUG #19042: Option --help not recognized at the end of command line in pg_restore

От
Daniel Gustafsson
Дата:
> On 10 Sep 2025, at 07:26, Peter Eisentraut <peter@eisentraut.org> wrote:
>
> On 03.09.25 21:34, Andres Freund wrote:
>> So +many for recognizing --help (and I'd say -?) everywhere, not just as the
>> first argument. I never understood why we don't do that.
>
> I think in the olden days we didn't have universal getopt_long() support, so it was hardcoded.  I don't see a problem
withchanging it. 

That's probably an accurate description.  I am writing up a patch to move it
into long option processing to see what it would look like, will share soon.

--
Daniel Gustafsson