pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #19042: Option --help not recognized at the end of command line in pg_restore
20+ messages / 8 participants
[nested] [flat]
* BUG #19042: Option --help not recognized at the end of command line in pg_restore
@ 2025-09-03 11:07 PG Bug reporting form <noreply@postgresql.org>
0 siblings, 1 reply; 20+ messages in thread
From: PG Bug reporting form @ 2025-09-03 11:07 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org; +Cc: matthias.hoermann@saltation.com
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.
```
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: BUG #19042: Option --help not recognized at the end of command line in pg_restore
@ 2025-09-03 11:45 Daniel Gustafsson <daniel@yesql.se>
parent: PG Bug reporting form <noreply@postgresql.org>
0 siblings, 1 reply; 20+ messages in thread
From: Daniel Gustafsson @ 2025-09-03 11:45 UTC (permalink / raw)
To: matthias.hoermann@saltation.com; pgsql-bugs@lists.postgresql.org
> 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
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: BUG #19042: Option --help not recognized at the end of command line in pg_restore
@ 2025-09-03 11:48 Matthias Hörmann <matthias.hoermann@saltation.com>
parent: Daniel Gustafsson <daniel@yesql.se>
0 siblings, 2 replies; 20+ messages in thread
From: Matthias Hörmann @ 2025-09-03 11:48 UTC (permalink / raw)
To: Daniel Gustafsson <daniel@yesql.se>; +Cc: pgsql-bugs@lists.postgresql.org
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.
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: BUG #19042: Option --help not recognized at the end of command line in pg_restore
@ 2025-09-03 14:57 Tom Lane <tgl@sss.pgh.pa.us>
parent: Matthias Hörmann <matthias.hoermann@saltation.com>
1 sibling, 2 replies; 20+ messages in thread
From: Tom Lane @ 2025-09-03 14:57 UTC (permalink / raw)
To: Matthias Hörmann <matthias.hoermann@saltation.com>; +Cc: Daniel Gustafsson <daniel@yesql.se>; pgsql-bugs@lists.postgresql.org
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
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: BUG #19042: Option --help not recognized at the end of command line in pg_restore
@ 2025-09-03 19:09 Daniel Gustafsson <daniel@yesql.se>
parent: Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 1 reply; 20+ messages in thread
From: Daniel Gustafsson @ 2025-09-03 19:09 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Matthias Hörmann <matthias.hoermann@saltation.com>; pgsql-bugs@lists.postgresql.org
> 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
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: BUG #19042: Option --help not recognized at the end of command line in pg_restore
@ 2025-09-03 19:22 Tom Lane <tgl@sss.pgh.pa.us>
parent: Daniel Gustafsson <daniel@yesql.se>
0 siblings, 0 replies; 20+ messages in thread
From: Tom Lane @ 2025-09-03 19:22 UTC (permalink / raw)
To: Daniel Gustafsson <daniel@yesql.se>; +Cc: Matthias Hörmann <matthias.hoermann@saltation.com>; pgsql-bugs@lists.postgresql.org
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
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: BUG #19042: Option --help not recognized at the end of command line in pg_restore
@ 2025-09-03 19:34 Andres Freund <andres@anarazel.de>
parent: Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 1 reply; 20+ messages in thread
From: Andres Freund @ 2025-09-03 19:34 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Matthias Hörmann <matthias.hoermann@saltation.com>; Daniel Gustafsson <daniel@yesql.se>; pgsql-bugs@lists.postgresql.org
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
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: BUG #19042: Option --help not recognized at the end of command line in pg_restore
@ 2025-09-03 20:58 Greg Sabino Mullane <htamfids@gmail.com>
parent: Matthias Hörmann <matthias.hoermann@saltation.com>
1 sibling, 0 replies; 20+ messages in thread
From: Greg Sabino Mullane @ 2025-09-03 20:58 UTC (permalink / raw)
To: Matthias Hörmann <matthias.hoermann@saltation.com>; +Cc: Daniel Gustafsson <daniel@yesql.se>; pgsql-bugs@lists.postgresql.org
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
--
Crunchy Data - https://www.crunchydata.com
Enterprise Postgres Software Products & Tech Support
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: BUG #19042: Option --help not recognized at the end of command line in pg_restore
@ 2025-09-10 05:26 Peter Eisentraut <peter@eisentraut.org>
parent: Andres Freund <andres@anarazel.de>
0 siblings, 1 reply; 20+ messages in thread
From: Peter Eisentraut @ 2025-09-10 05:26 UTC (permalink / raw)
To: Andres Freund <andres@anarazel.de>; Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Matthias Hörmann <matthias.hoermann@saltation.com>; Daniel Gustafsson <daniel@yesql.se>; pgsql-bugs@lists.postgresql.org
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.
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: BUG #19042: Option --help not recognized at the end of command line in pg_restore
@ 2025-09-10 09:24 Daniel Gustafsson <daniel@yesql.se>
parent: Peter Eisentraut <peter@eisentraut.org>
0 siblings, 1 reply; 20+ messages in thread
From: Daniel Gustafsson @ 2025-09-10 09:24 UTC (permalink / raw)
To: Peter Eisentraut <peter@eisentraut.org>; +Cc: Andres Freund <andres@anarazel.de>; Tom Lane <tgl@sss.pgh.pa.us>; Matthias Hörmann <matthias.hoermann@saltation.com>; pgsql-bugs@lists.postgresql.org
> 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 with changing 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
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: BUG #19042: Option --help not recognized at the end of command line in pg_restore
@ 2025-10-22 21:23 Nathan Bossart <nathandbossart@gmail.com>
parent: Daniel Gustafsson <daniel@yesql.se>
0 siblings, 2 replies; 20+ messages in thread
From: Nathan Bossart @ 2025-10-22 21:23 UTC (permalink / raw)
To: Daniel Gustafsson <daniel@yesql.se>; +Cc: Peter Eisentraut <peter@eisentraut.org>; Andres Freund <andres@anarazel.de>; Tom Lane <tgl@sss.pgh.pa.us>; Matthias Hörmann <matthias.hoermann@saltation.com>; pgsql-bugs@lists.postgresql.org
On Wed, Sep 10, 2025 at 11:24:36AM +0200, Daniel Gustafsson wrote:
> I am writing up a patch to move it into long option processing to see
> what it would look like, will share soon.
Are you still planning to work on this one?
--
nathan
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: BUG #19042: Option --help not recognized at the end of command line in pg_restore
@ 2025-10-22 21:53 Daniel Gustafsson <daniel@yesql.se>
parent: Nathan Bossart <nathandbossart@gmail.com>
1 sibling, 0 replies; 20+ messages in thread
From: Daniel Gustafsson @ 2025-10-22 21:53 UTC (permalink / raw)
To: Nathan Bossart <nathandbossart@gmail.com>; +Cc: Peter Eisentraut <peter@eisentraut.org>; Andres Freund <andres@anarazel.de>; Tom Lane <tgl@sss.pgh.pa.us>; Matthias Hörmann <matthias.hoermann@saltation.com>; pgsql-bugs@lists.postgresql.org
> On 22 Oct 2025, at 23:23, Nathan Bossart <nathandbossart@gmail.com> wrote:
>
> On Wed, Sep 10, 2025 at 11:24:36AM +0200, Daniel Gustafsson wrote:
>> I am writing up a patch to move it into long option processing to see
>> what it would look like, will share soon.
>
> Are you still planning to work on this one?
It's mostly done but got bumped off the TODO due to finalizing talk for
PGConf.EU, will send a patch shortly.
--
Daniel Gustafsson
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: BUG #19042: Option --help not recognized at the end of command line in pg_restore
@ 2025-10-24 22:26 Daniel Gustafsson <daniel@yesql.se>
parent: Nathan Bossart <nathandbossart@gmail.com>
1 sibling, 2 replies; 20+ messages in thread
From: Daniel Gustafsson @ 2025-10-24 22:26 UTC (permalink / raw)
To: Nathan Bossart <nathandbossart@gmail.com>; +Cc: Peter Eisentraut <peter@eisentraut.org>; Andres Freund <andres@anarazel.de>; Tom Lane <tgl@sss.pgh.pa.us>; Matthias Hörmann <matthias.hoermann@saltation.com>; pgsql-bugs@lists.postgresql.org
> On 22 Oct 2025, at 23:23, Nathan Bossart <nathandbossart@gmail.com> wrote:
>
> On Wed, Sep 10, 2025 at 11:24:36AM +0200, Daniel Gustafsson wrote:
>> I am writing up a patch to move it into long option processing to see
>> what it would look like, will share soon.
>
> Are you still planning to work on this one?
Attached is a v1 which converts all the apps in the tree to allow version and
help arguments at any position.
There was quite the variety of how the help/version arguments were handled,
some apps had partial support in the longopts, some had full support and some
had none. The idea was to make handling consistent across the binaries without
introducing any dependencies or build time changes.
While hacking on this it seemed like a good idea to move to using progname
consistently, and reduce scope in some places from global variables, but
looking at it now I'm less convinced. At the very least it should be ripped
out into its own patch but for now those changes are left in there.
It's far from an exciting patchset but it would be nice to get it done once and
for all. 0002 is a small change to make sure all apps exit with the same code,
I was unable to find a documented rationale for exit(2) so I think it's an
oversight.
--
Daniel Gustafsson
Attachments:
[application/octet-stream] v1-0001-Handle-help-and-version-as-normal-commandline-par.patch (81.8K, ../../B8FA8D64-5575-41F1-9F3B-DF603495309A@yesql.se/2-v1-0001-Handle-help-and-version-as-normal-commandline-par.patch)
download | inline diff:
From 4e2a56a6023229956063fe0feb9d0790c2a7c9cb Mon Sep 17 00:00:00 2001
From: Daniel Gustafsson <dgustafsson@postgresql.org>
Date: Wed, 10 Sep 2025 12:44:30 +0200
Subject: [PATCH v1 1/2] Handle --help and --version as normal commandline
parameters
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Traditionally all postgres apps has treated --help, -?, --version and
-V as special case options which have to be the first parameter in the
commandline, else they are considered unrecognized. This is not the
typical way to handle parameters in command line utilities, leading to
a bad user experience when a documented parameter is erroring out with
an unrecognized error.
This moves --help, -?, --version and -V into the common command line
parameter processing allowing them to be used at any argument position.
It turned out that our apps had very varied support for these in the
long_options array and getopt_long call. Some apps had the long option
defined but not the short option, some had both and some had neither of
them. Handling the actual parameters was also done in different ways,
some used inline code and others the handle_help_version_opts helper.
psql was its own case which had both, so removing the position one code
was all that was needed. The getopt_long handling in psql is now the
one place which is a little different from the others as it's left the
way it was given that it already worked.
Since getopt_long will return '?' for invalid parameters as well as for
the -? parameter without any way to distinguish the case at hand, there
is a special function added which is used to separate the two.
While there, ensure that progname is used consistently when printing
the name of the app, and move progname from the global namespace to
improve consistency across the code. TODO: this part of the patch
should probably be either ripped out or at least separated into its
own commit.
Author: Daniel Gustafsson <daniel@yesql.se>
Reviewed-by: ...
Reported-by: Matthias Hörmann <matthias.hoermann@saltation.com>
Discussion: https://postgr.es/m/19042-347869ae37c993f4@postgresql.org
---
contrib/oid2name/oid2name.c | 38 ++++++++-------
contrib/vacuumlo/vacuumlo.c | 33 ++++++-------
src/bin/initdb/initdb.c | 33 ++++++-------
src/bin/pg_amcheck/pg_amcheck.c | 21 +++++++--
src/bin/pg_archivecleanup/pg_archivecleanup.c | 43 +++++++++--------
src/bin/pg_basebackup/pg_basebackup.c | 39 ++++++++--------
src/bin/pg_basebackup/pg_createsubscriber.c | 38 +++++++--------
src/bin/pg_basebackup/pg_receivewal.c | 38 +++++++--------
src/bin/pg_basebackup/pg_recvlogical.c | 38 +++++++--------
src/bin/pg_checksums/pg_checksums.c | 38 +++++++--------
src/bin/pg_combinebackup/pg_combinebackup.c | 19 +++++++-
src/bin/pg_controldata/pg_controldata.c | 33 +++++++------
src/bin/pg_ctl/pg_ctl.c | 38 +++++++--------
src/bin/pg_dump/pg_dump.c | 36 ++++++++-------
src/bin/pg_dump/pg_dumpall.c | 40 +++++++++-------
src/bin/pg_dump/pg_restore.c | 36 +++++++++------
src/bin/pg_resetwal/pg_resetwal.c | 41 +++++++++--------
src/bin/pg_rewind/pg_rewind.c | 38 ++++++++-------
src/bin/pg_test_fsync/pg_test_fsync.c | 42 +++++++++++------
src/bin/pg_test_timing/pg_test_timing.c | 43 +++++++++++------
src/bin/pg_upgrade/option.c | 46 +++++++++++--------
src/bin/pg_verifybackup/pg_verifybackup.c | 40 ++++++++--------
src/bin/pg_waldump/pg_waldump.c | 38 ++++++++-------
src/bin/pg_walsummary/pg_walsummary.c | 21 +++++++--
src/bin/pgbench/pgbench.c | 35 +++++++-------
src/bin/psql/startup.c | 14 ------
src/bin/scripts/clusterdb.c | 22 +++++++--
src/bin/scripts/createdb.c | 22 +++++++--
src/bin/scripts/createuser.c | 21 +++++++--
src/bin/scripts/dropdb.c | 22 +++++++--
src/bin/scripts/dropuser.c | 22 +++++++--
src/bin/scripts/pg_isready.c | 21 +++++++--
src/bin/scripts/reindexdb.c | 21 +++++++--
src/bin/scripts/vacuumdb.c | 22 +++++++--
src/bin/scripts/vacuuming.c | 1 -
src/fe_utils/option_utils.c | 31 ++++++-------
src/include/fe_utils/option_utils.h | 5 --
src/include/port.h | 3 ++
src/interfaces/ecpg/preproc/ecpg.c | 38 ++++++++-------
src/port/Makefile | 1 +
src/port/meson.build | 1 +
src/port/pg_option_utils.c | 30 ++++++++++++
src/test/regress/pg_regress.c | 3 +-
43 files changed, 729 insertions(+), 476 deletions(-)
create mode 100644 src/port/pg_option_utils.c
diff --git a/contrib/oid2name/oid2name.c b/contrib/oid2name/oid2name.c
index 51802907138..4f7a45363ac 100644
--- a/contrib/oid2name/oid2name.c
+++ b/contrib/oid2name/oid2name.c
@@ -77,7 +77,7 @@ get_opts(int argc, char **argv, struct options *my_opts)
{"username", required_argument, NULL, 'U'},
{"version", no_argument, NULL, 'V'},
{"extended", no_argument, NULL, 'x'},
- {"help", no_argument, NULL, '?'},
+ {"help", no_argument, NULL, 1},
{NULL, 0, NULL, 0}
};
@@ -101,22 +101,8 @@ get_opts(int argc, char **argv, struct options *my_opts)
my_opts->username = NULL;
my_opts->progname = progname;
- if (argc > 1)
- {
- if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
- {
- help(progname);
- exit(0);
- }
- if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
- {
- puts("oid2name (PostgreSQL) " PG_VERSION);
- exit(0);
- }
- }
-
/* get opts */
- while ((c = getopt_long(argc, argv, "d:f:h:H:io:p:qsSt:U:x", long_options, &optindex)) != -1)
+ while ((c = getopt_long(argc, argv, "d:f:h:H:io:p:qsSt:U:Vx?", long_options, &optindex)) != -1)
{
switch (c)
{
@@ -176,11 +162,31 @@ get_opts(int argc, char **argv, struct options *my_opts)
my_opts->username = pg_strdup(optarg);
break;
+ /* display version and exit */
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
+ exit(0);
+
/* display extra columns */
case 'x':
my_opts->extended = true;
break;
+ /* display help and exit */
+ case 1:
+ help(progname);
+ exit(0);
+
+ /* -? help or invalid option */
+ case '?':
+ if (is_help_param(argc, argv, optind))
+ {
+ help(progname);
+ exit(0);
+ }
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+ exit(1);
+
default:
/* getopt_long already emitted a complaint */
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
diff --git a/contrib/vacuumlo/vacuumlo.c b/contrib/vacuumlo/vacuumlo.c
index 16a450c4386..faf4bef7cbe 100644
--- a/contrib/vacuumlo/vacuumlo.c
+++ b/contrib/vacuumlo/vacuumlo.c
@@ -446,7 +446,7 @@ main(int argc, char **argv)
{"version", no_argument, NULL, 'V'},
{"no-password", no_argument, NULL, 'w'},
{"password", no_argument, NULL, 'W'},
- {"help", no_argument, NULL, '?'},
+ {"help", no_argument, NULL, 1},
{NULL, 0, NULL, 0}
};
@@ -471,21 +471,7 @@ main(int argc, char **argv)
param.transaction_limit = 1000;
/* Process command-line arguments */
- if (argc > 1)
- {
- if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
- {
- usage(progname);
- exit(0);
- }
- if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
- {
- puts("vacuumlo (PostgreSQL) " PG_VERSION);
- exit(0);
- }
- }
-
- while ((c = getopt_long(argc, argv, "h:l:np:U:vwW", long_options, &optindex)) != -1)
+ while ((c = getopt_long(argc, argv, "h:l:np:U:vVwW?", long_options, &optindex)) != -1)
{
switch (c)
{
@@ -513,12 +499,27 @@ main(int argc, char **argv)
case 'v':
param.verbose = 1;
break;
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
+ exit(0);
case 'w':
param.pg_prompt = TRI_NO;
break;
case 'W':
param.pg_prompt = TRI_YES;
break;
+ case 1:
+ usage(progname);
+ exit(0);
+ /* -? or invalid option */
+ case '?':
+ if (is_help_param(argc, argv, optind))
+ {
+ usage(progname);
+ exit(0);
+ }
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+ exit(1);
default:
/* getopt_long already emitted a complaint */
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index 92fe2f531f7..0c47922d656 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -3172,7 +3172,7 @@ main(int argc, char *argv[])
{"pwprompt", no_argument, NULL, 'W'},
{"pwfile", required_argument, NULL, 9},
{"username", required_argument, NULL, 'U'},
- {"help", no_argument, NULL, '?'},
+ {"help", no_argument, NULL, 22},
{"version", no_argument, NULL, 'V'},
{"debug", no_argument, NULL, 'd'},
{"show", no_argument, NULL, 's'},
@@ -3220,23 +3220,9 @@ main(int argc, char *argv[])
progname = get_progname(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("initdb"));
- if (argc > 1)
- {
- if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
- {
- usage(progname);
- exit(0);
- }
- if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
- {
- puts("initdb (PostgreSQL) " PG_VERSION);
- exit(0);
- }
- }
-
/* process command-line options */
- while ((c = getopt_long(argc, argv, "A:c:dD:E:gkL:nNsST:U:WX:",
+ while ((c = getopt_long(argc, argv, "A:c:dD:E:gkL:nNsST:U:VWX:?",
long_options, &option_index)) != -1)
{
switch (c)
@@ -3392,6 +3378,21 @@ main(int argc, char *argv[])
case 21:
sync_data_files = false;
break;
+ case 22:
+ usage(progname);
+ exit(0);
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
+ exit(0);
+ /* -? help or invalid option */
+ case '?':
+ if (is_help_param(argc, argv, optind))
+ {
+ usage(progname);
+ exit(0);
+ }
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+ exit(1);
default:
/* getopt_long already emitted a complaint */
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
diff --git a/src/bin/pg_amcheck/pg_amcheck.c b/src/bin/pg_amcheck/pg_amcheck.c
index 2b1fd566c35..fb82bd89755 100644
--- a/src/bin/pg_amcheck/pg_amcheck.c
+++ b/src/bin/pg_amcheck/pg_amcheck.c
@@ -273,6 +273,8 @@ main(int argc, char *argv[])
{"install-missing", optional_argument, NULL, 13},
{"checkunique", no_argument, NULL, 14},
+ {"version", no_argument, NULL, 'V'},
+ {"help", no_argument, NULL, 15},
{NULL, 0, NULL, 0}
};
@@ -293,10 +295,8 @@ main(int argc, char *argv[])
progname = get_progname(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_amcheck"));
- handle_help_version_opts(argc, argv, progname, help);
-
/* process command-line options */
- while ((c = getopt_long(argc, argv, "ad:D:eh:Hi:I:j:p:Pr:R:s:S:t:T:U:vwW",
+ while ((c = getopt_long(argc, argv, "ad:D:eh:Hi:I:j:p:Pr:R:s:S:t:T:U:vVwW?",
long_options, &optindex)) != -1)
{
char *endptr;
@@ -372,6 +372,9 @@ main(int argc, char *argv[])
opts.verbose = true;
pg_logging_increase_verbosity();
break;
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
+ exit(0);
case 'w':
prompt_password = TRI_NO;
break;
@@ -442,6 +445,18 @@ main(int argc, char *argv[])
case 14:
opts.checkunique = true;
break;
+ case 15:
+ help(progname);
+ exit(0);
+ /* -? or invalid option */
+ case '?':
+ if (is_help_param(argc, argv, optind))
+ {
+ help(progname);
+ exit(0);
+ }
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+ exit(1);
default:
/* getopt_long already emitted a complaint */
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
diff --git a/src/bin/pg_archivecleanup/pg_archivecleanup.c b/src/bin/pg_archivecleanup/pg_archivecleanup.c
index c25348bcb85..700c06a3f44 100644
--- a/src/bin/pg_archivecleanup/pg_archivecleanup.c
+++ b/src/bin/pg_archivecleanup/pg_archivecleanup.c
@@ -19,8 +19,6 @@
#include "common/logging.h"
#include "getopt_long.h"
-static const char *progname;
-
/* Options and defaults */
static bool dryrun = false; /* are we performing a dry-run operation? */
static bool cleanBackupHistory = false; /* remove files including backup
@@ -181,7 +179,7 @@ CleanupPriorWALFiles(void)
* and decide whether we need cleanup
*/
static void
-SetWALFileNameForCleanup(void)
+SetWALFileNameForCleanup(const char *progname)
{
bool fnameOK = false;
@@ -255,7 +253,7 @@ SetWALFileNameForCleanup(void)
*/
static void
-usage(void)
+usage(const char *progname)
{
printf(_("%s removes older WAL files from PostgreSQL archives.\n\n"), progname);
printf(_("Usage:\n"));
@@ -291,29 +289,19 @@ main(int argc, char **argv)
{"debug", no_argument, NULL, 'd'},
{"dry-run", no_argument, NULL, 'n'},
{"strip-extension", required_argument, NULL, 'x'},
+ {"version", no_argument, NULL, 'V'},
+ {"help", no_argument, NULL, 1},
{NULL, 0, NULL, 0}
};
int c;
+ const char *progname;
+
pg_logging_init(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_archivecleanup"));
progname = get_progname(argv[0]);
- if (argc > 1)
- {
- if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
- {
- usage();
- exit(0);
- }
- if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
- {
- puts("pg_archivecleanup (PostgreSQL) " PG_VERSION);
- exit(0);
- }
- }
-
- while ((c = getopt_long(argc, argv, "bdnx:", long_options, NULL)) != -1)
+ while ((c = getopt_long(argc, argv, "bdnx:V?", long_options, NULL)) != -1)
{
switch (c)
{
@@ -326,10 +314,25 @@ main(int argc, char **argv)
case 'n': /* Dry-Run mode */
dryrun = true;
break;
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
+ exit(0);
case 'x':
additional_ext = pg_strdup(optarg); /* Extension to remove
* from xlogfile names */
break;
+ case 1:
+ usage(progname);
+ exit(0);
+ /* -? or invalid option */
+ case '?':
+ if (is_help_param(argc, argv, optind))
+ {
+ usage(progname);
+ exit(0);
+ }
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+ exit(1);
default:
/* getopt already emitted a complaint */
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
@@ -383,7 +386,7 @@ main(int argc, char **argv)
/*
* Check filename is a valid name, then process to find cut-off
*/
- SetWALFileNameForCleanup();
+ SetWALFileNameForCleanup(progname);
pg_log_debug("keeping WAL file \"%s/%s\" and later",
archiveLocation, exclusiveCleanupFileName);
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index 0a3ca4315de..d34ed3751e0 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -195,7 +195,7 @@ static volatile LONG has_xlogendptr = 0;
static PQExpBuffer recoveryconfcontents = NULL;
/* Function headers */
-static void usage(void);
+static void usage(const char *progname);
static void verify_dir_is_empty_or_create(char *dirname, bool *created, bool *found);
static void progress_update_filename(const char *filename);
static void progress_report(int tablespacenum, bool force, bool finished);
@@ -388,7 +388,7 @@ tablespace_list_append(const char *arg)
static void
-usage(void)
+usage(const char *progname)
{
printf(_("%s takes a base backup of a running PostgreSQL server.\n\n"),
progname);
@@ -2357,7 +2357,7 @@ int
main(int argc, char **argv)
{
static struct option long_options[] = {
- {"help", no_argument, NULL, '?'},
+ {"help", no_argument, NULL, 9},
{"version", no_argument, NULL, 'V'},
{"pgdata", required_argument, NULL, 'D'},
{"format", required_argument, NULL, 'F'},
@@ -2400,6 +2400,7 @@ main(int argc, char **argv)
char *compression_algorithm = "none";
char *compression_detail = NULL;
char *incremental_manifest = NULL;
+ const char *progname;
CompressionLocation compressloc = COMPRESS_LOCATION_UNSPECIFIED;
pg_compress_specification client_compress;
@@ -2407,24 +2408,9 @@ main(int argc, char **argv)
progname = get_progname(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_basebackup"));
- if (argc > 1)
- {
- if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
- {
- usage();
- exit(0);
- }
- else if (strcmp(argv[1], "-V") == 0
- || strcmp(argv[1], "--version") == 0)
- {
- puts("pg_basebackup (PostgreSQL) " PG_VERSION);
- exit(0);
- }
- }
-
atexit(cleanup_directories_atexit);
- while ((c = getopt_long(argc, argv, "c:Cd:D:F:h:i:l:nNp:Pr:Rs:S:t:T:U:vwWX:zZ:",
+ while ((c = getopt_long(argc, argv, "c:Cd:D:F:h:i:l:nNp:Pr:Rs:S:t:T:U:vVwWX:zZ:?",
long_options, &option_index)) != -1)
{
switch (c)
@@ -2511,6 +2497,9 @@ main(int argc, char **argv)
case 'v':
verbose++;
break;
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
+ exit(0);
case 'w':
dbgetpassword = -1;
break;
@@ -2571,6 +2560,18 @@ main(int argc, char **argv)
if (!parse_sync_method(optarg, &sync_method))
exit(1);
break;
+ case 9:
+ usage(progname);
+ exit(0);
+ /* -? or invalid option */
+ case '?':
+ if (is_help_param(argc, argv, optind))
+ {
+ usage(progname);
+ exit(0);
+ }
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+ exit(1);
default:
/* getopt_long already emitted a complaint */
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
diff --git a/src/bin/pg_basebackup/pg_createsubscriber.c b/src/bin/pg_basebackup/pg_createsubscriber.c
index 9fa5caaf91d..442ad1445ae 100644
--- a/src/bin/pg_basebackup/pg_createsubscriber.c
+++ b/src/bin/pg_basebackup/pg_createsubscriber.c
@@ -77,7 +77,7 @@ struct LogicalRepInfos
};
static void cleanup_objects_atexit(void);
-static void usage();
+static void usage(const char *progname);
static char *get_base_conninfo(const char *conninfo, char **dbname);
static char *get_sub_conninfo(const struct CreateSubscriberOptions *opt);
static char *get_exec_path(const char *argv0, const char *progname);
@@ -240,7 +240,7 @@ cleanup_objects_atexit(void)
}
static void
-usage(void)
+usage(const char *progname)
{
printf(_("%s creates a new logical replica from a standby server.\n\n"),
progname);
@@ -2047,7 +2047,7 @@ main(int argc, char **argv)
{"subscriber-username", required_argument, NULL, 'U'},
{"verbose", no_argument, NULL, 'v'},
{"version", no_argument, NULL, 'V'},
- {"help", no_argument, NULL, '?'},
+ {"help", no_argument, NULL, 6},
{"config-file", required_argument, NULL, 1},
{"publication", required_argument, NULL, 2},
{"replication-slot", required_argument, NULL, 3},
@@ -2078,21 +2078,6 @@ main(int argc, char **argv)
progname = get_progname(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_basebackup"));
- if (argc > 1)
- {
- if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
- {
- usage();
- exit(0);
- }
- else if (strcmp(argv[1], "-V") == 0
- || strcmp(argv[1], "--version") == 0)
- {
- puts("pg_createsubscriber (PostgreSQL) " PG_VERSION);
- exit(0);
- }
- }
-
/* Default settings */
subscriber_dir = NULL;
opt.config_file = NULL;
@@ -2124,7 +2109,7 @@ main(int argc, char **argv)
get_restricted_token();
- while ((c = getopt_long(argc, argv, "ad:D:np:P:s:t:TU:v",
+ while ((c = getopt_long(argc, argv, "ad:D:np:P:s:t:TU:vV?",
long_options, &option_index)) != -1)
{
switch (c)
@@ -2170,6 +2155,9 @@ main(int argc, char **argv)
case 'v':
pg_logging_increase_verbosity();
break;
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
+ exit(0);
case 1:
opt.config_file = pg_strdup(optarg);
break;
@@ -2206,6 +2194,18 @@ main(int argc, char **argv)
else
pg_fatal("object type \"%s\" specified more than once for --clean", optarg);
break;
+ case 6:
+ usage(progname);
+ exit(0);
+ /* -? help or invalid option */
+ case '?':
+ if (is_help_param(argc, argv, optind))
+ {
+ usage(progname);
+ exit(0);
+ }
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+ exit(1);
default:
/* getopt_long already emitted a complaint */
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
diff --git a/src/bin/pg_basebackup/pg_receivewal.c b/src/bin/pg_basebackup/pg_receivewal.c
index 289ca14dcfe..c220dbb1ce7 100644
--- a/src/bin/pg_basebackup/pg_receivewal.c
+++ b/src/bin/pg_basebackup/pg_receivewal.c
@@ -56,7 +56,7 @@ static pg_compress_algorithm compression_algorithm = PG_COMPRESSION_NONE;
static XLogRecPtr endpos = InvalidXLogRecPtr;
-static void usage(void);
+static void usage(const char *progname);
static DIR *get_destination_dir(char *dest_folder);
static void close_destination_dir(DIR *dest_dir, char *dest_folder);
static XLogRecPtr FindStreamingStart(uint32 *tli);
@@ -72,7 +72,7 @@ disconnect_atexit(void)
}
static void
-usage(void)
+usage(const char *progname)
{
printf(_("%s receives PostgreSQL streaming write-ahead logs.\n\n"),
progname);
@@ -624,7 +624,7 @@ int
main(int argc, char **argv)
{
static struct option long_options[] = {
- {"help", no_argument, NULL, '?'},
+ {"help", no_argument, NULL, 6},
{"version", no_argument, NULL, 'V'},
{"directory", required_argument, NULL, 'D'},
{"dbname", required_argument, NULL, 'd'},
@@ -662,22 +662,7 @@ main(int argc, char **argv)
progname = get_progname(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_basebackup"));
- if (argc > 1)
- {
- if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
- {
- usage();
- exit(0);
- }
- else if (strcmp(argv[1], "-V") == 0 ||
- strcmp(argv[1], "--version") == 0)
- {
- puts("pg_receivewal (PostgreSQL) " PG_VERSION);
- exit(0);
- }
- }
-
- while ((c = getopt_long(argc, argv, "d:D:E:h:np:s:S:U:vwWZ:",
+ while ((c = getopt_long(argc, argv, "d:D:E:h:np:s:S:U:vVwWZ:?",
long_options, &option_index)) != -1)
{
switch (c)
@@ -718,6 +703,9 @@ main(int argc, char **argv)
case 'v':
verbose++;
break;
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
+ exit(0);
case 'w':
dbgetpassword = -1;
break;
@@ -743,6 +731,18 @@ main(int argc, char **argv)
case 5:
do_sync = false;
break;
+ case 6:
+ usage(progname);
+ exit(0);
+ /* -? help or invalid option */
+ case '?':
+ if (is_help_param(argc, argv, optind))
+ {
+ usage(progname);
+ exit(0);
+ }
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+ exit(1);
default:
/* getopt_long already emitted a complaint */
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
diff --git a/src/bin/pg_basebackup/pg_recvlogical.c b/src/bin/pg_basebackup/pg_recvlogical.c
index 7a4d1a2d2ca..b178571e62d 100644
--- a/src/bin/pg_basebackup/pg_recvlogical.c
+++ b/src/bin/pg_basebackup/pg_recvlogical.c
@@ -71,7 +71,7 @@ static bool output_needs_fsync = false;
static XLogRecPtr output_written_lsn = InvalidXLogRecPtr;
static XLogRecPtr output_fsync_lsn = InvalidXLogRecPtr;
-static void usage(void);
+static void usage(const char *progname);
static void StreamLogicalLog(void);
static bool flushAndSendFeedback(PGconn *conn, TimestampTz *now);
static void prepareToTerminate(PGconn *conn, XLogRecPtr endpos,
@@ -79,7 +79,7 @@ static void prepareToTerminate(PGconn *conn, XLogRecPtr endpos,
XLogRecPtr lsn);
static void
-usage(void)
+usage(const char *progname)
{
printf(_("%s controls PostgreSQL logical decoding streams.\n\n"),
progname);
@@ -705,7 +705,7 @@ main(int argc, char **argv)
{"two-phase", no_argument, NULL, 't'}, /* deprecated */
{"verbose", no_argument, NULL, 'v'},
{"version", no_argument, NULL, 'V'},
- {"help", no_argument, NULL, '?'},
+ {"help", no_argument, NULL, 6},
/* connection options */
{"dbname", required_argument, NULL, 'd'},
{"host", required_argument, NULL, 'h'},
@@ -737,22 +737,7 @@ main(int argc, char **argv)
progname = get_progname(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_basebackup"));
- if (argc > 1)
- {
- if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
- {
- usage();
- exit(0);
- }
- else if (strcmp(argv[1], "-V") == 0 ||
- strcmp(argv[1], "--version") == 0)
- {
- puts("pg_recvlogical (PostgreSQL) " PG_VERSION);
- exit(0);
- }
- }
-
- while ((c = getopt_long(argc, argv, "E:f:F:ntvd:h:p:U:wWI:o:P:s:S:",
+ while ((c = getopt_long(argc, argv, "E:f:F:ntvd:h:p:U:VwWI:o:P:s:S:?",
long_options, &option_index)) != -1)
{
switch (c)
@@ -857,6 +842,21 @@ main(int argc, char **argv)
slot_exists_ok = true;
break;
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
+ exit(0);
+ case 6:
+ usage(progname);
+ exit(0);
+ /* -? help or invalid option */
+ case '?':
+ if (is_help_param(argc, argv, optind))
+ {
+ usage(progname);
+ exit(0);
+ }
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+ exit(1);
default:
/* getopt_long already emitted a complaint */
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
diff --git a/src/bin/pg_checksums/pg_checksums.c b/src/bin/pg_checksums/pg_checksums.c
index 46cb2f36efa..1fdf8055946 100644
--- a/src/bin/pg_checksums/pg_checksums.c
+++ b/src/bin/pg_checksums/pg_checksums.c
@@ -55,8 +55,6 @@ typedef enum
static PgChecksumMode mode = PG_MODE_CHECK;
-static const char *progname;
-
/*
* Progress status information.
*/
@@ -65,7 +63,7 @@ static int64 current_size = 0;
static pg_time_t last_progress_report = 0;
static void
-usage(void)
+usage(const char *progname)
{
printf(_("%s enables, disables, or verifies data checksums in a PostgreSQL database cluster.\n\n"), progname);
printf(_("Usage:\n"));
@@ -442,6 +440,8 @@ main(int argc, char *argv[])
{"progress", no_argument, NULL, 'P'},
{"verbose", no_argument, NULL, 'v'},
{"sync-method", required_argument, NULL, 1},
+ {"version", no_argument, NULL, 'V'},
+ {"help", no_argument, NULL, 2},
{NULL, 0, NULL, 0}
};
@@ -451,26 +451,13 @@ main(int argc, char *argv[])
bool crc_ok;
uint32 major_version;
char *version_str;
+ const char *progname;
pg_logging_init(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_checksums"));
progname = get_progname(argv[0]);
- if (argc > 1)
- {
- if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
- {
- usage();
- exit(0);
- }
- if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
- {
- puts("pg_checksums (PostgreSQL) " PG_VERSION);
- exit(0);
- }
- }
-
- while ((c = getopt_long(argc, argv, "cdD:ef:NPv", long_options, &option_index)) != -1)
+ while ((c = getopt_long(argc, argv, "cdD:ef:NPvV?", long_options, &option_index)) != -1)
{
switch (c)
{
@@ -502,10 +489,25 @@ main(int argc, char *argv[])
case 'v':
verbose = true;
break;
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
+ exit(0);
case 1:
if (!parse_sync_method(optarg, &sync_method))
exit(1);
break;
+ case 2:
+ usage(progname);
+ exit(0);
+ /* -? or invalid option */
+ case '?':
+ if (is_help_param(argc, argv, optind))
+ {
+ usage(progname);
+ exit(0);
+ }
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+ exit(1);
default:
/* getopt_long already emitted a complaint */
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
diff --git a/src/bin/pg_combinebackup/pg_combinebackup.c b/src/bin/pg_combinebackup/pg_combinebackup.c
index 3a325127209..09b561908c1 100644
--- a/src/bin/pg_combinebackup/pg_combinebackup.c
+++ b/src/bin/pg_combinebackup/pg_combinebackup.c
@@ -143,6 +143,8 @@ main(int argc, char *argv[])
{"clone", no_argument, NULL, 4},
{"copy", no_argument, NULL, 5},
{"copy-file-range", no_argument, NULL, 6},
+ {"version", no_argument, NULL, 'V'},
+ {"help", no_argument, NULL, 7},
{NULL, 0, NULL, 0}
};
@@ -167,7 +169,6 @@ main(int argc, char *argv[])
pg_logging_init(argv[0]);
progname = get_progname(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_combinebackup"));
- handle_help_version_opts(argc, argv, progname, help);
memset(&opt, 0, sizeof(opt));
opt.manifest_checksums = CHECKSUM_TYPE_CRC32C;
@@ -175,7 +176,7 @@ main(int argc, char *argv[])
opt.copy_method = COPY_METHOD_COPY;
/* process command-line options */
- while ((c = getopt_long(argc, argv, "dknNo:T:",
+ while ((c = getopt_long(argc, argv, "dknNo:T:V?",
long_options, &optindex)) != -1)
{
switch (c)
@@ -221,6 +222,20 @@ main(int argc, char *argv[])
case 6:
opt.copy_method = COPY_METHOD_COPY_FILE_RANGE;
break;
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
+ exit(0);
+ case 7:
+ help(progname);
+ exit(0);
+ case '?':
+ if (is_help_param(argc, argv, optind))
+ {
+ help(progname);
+ exit(0);
+ }
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+ exit(1);
default:
/* getopt_long already emitted a complaint */
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
diff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c
index 10de058ce91..c4b050b9b96 100644
--- a/src/bin/pg_controldata/pg_controldata.c
+++ b/src/bin/pg_controldata/pg_controldata.c
@@ -90,6 +90,8 @@ main(int argc, char *argv[])
{
static struct option long_options[] = {
{"pgdata", required_argument, NULL, 'D'},
+ {"version", no_argument, NULL, 'V'},
+ {"help", no_argument, NULL, 1},
{NULL, 0, NULL, 0}
};
@@ -112,28 +114,29 @@ main(int argc, char *argv[])
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_controldata"));
progname = get_progname(argv[0]);
- if (argc > 1)
- {
- if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
- {
- usage(progname);
- exit(0);
- }
- if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
- {
- puts("pg_controldata (PostgreSQL) " PG_VERSION);
- exit(0);
- }
- }
-
- while ((c = getopt_long(argc, argv, "D:", long_options, NULL)) != -1)
+ while ((c = getopt_long(argc, argv, "D:V?", long_options, NULL)) != -1)
{
switch (c)
{
case 'D':
DataDir = optarg;
break;
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
+ exit(0);
+ case 1:
+ usage(progname);
+ exit(0);
+ /* -? or invalid option */
+ case '?':
+ if (is_help_param(argc, argv, optind))
+ {
+ usage(progname);
+ exit(0);
+ }
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+ exit(1);
default:
/* getopt_long already emitted a complaint */
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c
index 8a405ff122c..8995855537f 100644
--- a/src/bin/pg_ctl/pg_ctl.c
+++ b/src/bin/pg_ctl/pg_ctl.c
@@ -115,7 +115,7 @@ static HANDLE shutdownHandles[2];
static void write_stderr(const char *fmt,...) pg_attribute_printf(1, 2);
static void do_advice(void);
-static void do_help(void);
+static void do_help(const char *progname);
static void set_mode(char *modeopt);
static void set_sig(char *signame);
static void do_init(void);
@@ -1970,7 +1970,7 @@ do_advice(void)
static void
-do_help(void)
+do_help(const char *progname)
{
printf(_("%s is a utility to initialize, start, stop, or control a PostgreSQL server.\n\n"), progname);
printf(_("Usage:\n"));
@@ -2202,7 +2202,7 @@ int
main(int argc, char **argv)
{
static struct option long_options[] = {
- {"help", no_argument, NULL, '?'},
+ {"help", no_argument, NULL, 1},
{"version", no_argument, NULL, 'V'},
{"log", required_argument, NULL, 'l'},
{"mode", required_argument, NULL, 'm'},
@@ -2235,21 +2235,6 @@ main(int argc, char **argv)
/* Set restrictive mode mask until PGDATA permissions are checked */
umask(PG_MODE_MASK_OWNER);
- /* support --help and --version even if invoked as root */
- if (argc > 1)
- {
- if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
- {
- do_help();
- exit(0);
- }
- else if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
- {
- puts("pg_ctl (PostgreSQL) " PG_VERSION);
- exit(0);
- }
- }
-
/*
* Disallow running as root, to forestall any possible security holes.
*/
@@ -2270,7 +2255,7 @@ main(int argc, char **argv)
wait_seconds = atoi(env_wait);
/* process command-line options */
- while ((c = getopt_long(argc, argv, "cD:e:l:m:N:o:p:P:sS:t:U:wW",
+ while ((c = getopt_long(argc, argv, "cD:e:l:m:N:o:p:P:sS:t:U:VwW?",
long_options, &option_index)) != -1)
{
switch (c)
@@ -2353,6 +2338,21 @@ main(int argc, char **argv)
case 'c':
allow_core_files = true;
break;
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
+ exit(0);
+ case 1:
+ do_help(progname);
+ exit(0);
+ /* -? help or invalid option */
+ case '?':
+ if (is_help_param(argc, argv, optind))
+ {
+ do_help(progname);
+ exit(0);
+ }
+ do_advice();
+ exit(1);
default:
/* getopt_long already issued a suitable error message */
do_advice();
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 47913178a93..b452a0b95a4 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -487,7 +487,7 @@ main(int argc, char **argv)
{"no-acl", no_argument, NULL, 'x'},
{"compress", required_argument, NULL, 'Z'},
{"encoding", required_argument, NULL, 'E'},
- {"help", no_argument, NULL, '?'},
+ {"help", no_argument, NULL, 26},
{"version", no_argument, NULL, 'V'},
/*
@@ -554,23 +554,9 @@ main(int argc, char **argv)
progname = get_progname(argv[0]);
- if (argc > 1)
- {
- if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
- {
- help(progname);
- exit_nicely(0);
- }
- if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
- {
- puts("pg_dump (PostgreSQL) " PG_VERSION);
- exit_nicely(0);
- }
- }
-
InitDumpOptions(&dopt);
- while ((c = getopt_long(argc, argv, "abBcCd:e:E:f:F:h:j:n:N:Op:RsS:t:T:U:vwWxXZ:",
+ while ((c = getopt_long(argc, argv, "abBcCd:e:E:f:F:h:j:n:N:Op:RsS:t:T:U:vVwWxXZ:?",
long_options, &optindex)) != -1)
{
switch (c)
@@ -674,6 +660,10 @@ main(int argc, char **argv)
pg_logging_increase_verbosity();
break;
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
+ exit_nicely(0);
+
case 'w':
dopt.cparams.promptPassword = TRI_NO;
break;
@@ -802,6 +792,20 @@ main(int argc, char **argv)
dopt.restrict_key = pg_strdup(optarg);
break;
+ case 26:
+ help(progname);
+ exit_nicely(0);
+
+ /* -? help or invalid option */
+ case '?':
+ if (is_help_param(argc, argv, optind))
+ {
+ help(progname);
+ exit_nicely(0);
+ }
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+ exit_nicely(1);
+
default:
/* getopt_long already emitted a complaint */
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c
index bb451c1bae1..7952af6a5f4 100644
--- a/src/bin/pg_dump/pg_dumpall.c
+++ b/src/bin/pg_dump/pg_dumpall.c
@@ -55,7 +55,7 @@ typedef struct
#define SH_DEFINE
#include "lib/simplehash.h"
-static void help(void);
+static void help(const char *progname);
static void dropRoles(PGconn *conn);
static void dumpRoles(PGconn *conn);
@@ -187,6 +187,8 @@ main(int argc, char *argv[])
{"filter", required_argument, NULL, 8},
{"sequence-data", no_argument, &sequence_data, 1},
{"restrict-key", required_argument, NULL, 9},
+ {"version", no_argument, NULL, 'V'},
+ {"help", no_argument, NULL, 10},
{NULL, 0, NULL, 0}
};
@@ -214,20 +216,6 @@ main(int argc, char *argv[])
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_dump"));
progname = get_progname(argv[0]);
- if (argc > 1)
- {
- if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
- {
- help();
- exit_nicely(0);
- }
- if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
- {
- puts("pg_dumpall (PostgreSQL) " PG_VERSION);
- exit_nicely(0);
- }
- }
-
if ((ret = find_other_exec(argv[0], "pg_dump", PGDUMP_VERSIONSTR,
pg_dump_bin)) < 0)
{
@@ -246,7 +234,7 @@ main(int argc, char *argv[])
pgdumpopts = createPQExpBuffer();
- while ((c = getopt_long(argc, argv, "acd:E:f:gh:l:Op:rsS:tU:vwWx", long_options, &optindex)) != -1)
+ while ((c = getopt_long(argc, argv, "acd:E:f:gh:l:Op:rsS:tU:vVwWx?", long_options, &optindex)) != -1)
{
switch (c)
{
@@ -322,6 +310,10 @@ main(int argc, char *argv[])
appendPQExpBufferStr(pgdumpopts, " -v");
break;
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
+ exit_nicely(0);
+
case 'w':
prompt_password = TRI_NO;
appendPQExpBufferStr(pgdumpopts, " -w");
@@ -380,6 +372,20 @@ main(int argc, char *argv[])
appendShellString(pgdumpopts, optarg);
break;
+ case 10:
+ help(progname);
+ exit_nicely(0);
+
+ /* -? help or invalid option */
+ case '?':
+ if (is_help_param(argc, argv, optind))
+ {
+ help(progname);
+ exit_nicely(0);
+ }
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+ exit_nicely(1);
+
default:
/* getopt_long already emitted a complaint */
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
@@ -688,7 +694,7 @@ main(int argc, char *argv[])
static void
-help(void)
+help(const char *progname)
{
printf(_("%s exports a PostgreSQL database cluster as an SQL script.\n\n"), progname);
printf(_("Usage:\n"));
diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c
index c9776306c5c..dbef274d65c 100644
--- a/src/bin/pg_dump/pg_restore.c
+++ b/src/bin/pg_dump/pg_restore.c
@@ -142,6 +142,8 @@ main(int argc, char **argv)
{"statistics-only", no_argument, &statistics_only, 1},
{"filter", required_argument, NULL, 4},
{"restrict-key", required_argument, NULL, 6},
+ {"version", no_argument, NULL, 'V'},
+ {"help", no_argument, NULL, 7},
{NULL, 0, NULL, 0}
};
@@ -156,21 +158,7 @@ main(int argc, char **argv)
progname = get_progname(argv[0]);
- if (argc > 1)
- {
- if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
- {
- usage(progname);
- exit_nicely(0);
- }
- if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
- {
- puts("pg_restore (PostgreSQL) " PG_VERSION);
- exit_nicely(0);
- }
- }
-
- while ((c = getopt_long(argc, argv, "acCd:ef:F:h:I:j:lL:n:N:Op:P:RsS:t:T:U:vwWx1",
+ while ((c = getopt_long(argc, argv, "acCd:ef:F:h:I:j:lL:n:N:Op:P:RsS:t:T:U:vVwWx1?",
cmdopts, NULL)) != -1)
{
switch (c)
@@ -273,6 +261,10 @@ main(int argc, char **argv)
pg_logging_increase_verbosity();
break;
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
+ exit_nicely(0);
+
case 'w':
opts->cparams.promptPassword = TRI_NO;
break;
@@ -321,6 +313,20 @@ main(int argc, char **argv)
opts->restrict_key = pg_strdup(optarg);
break;
+ case 7:
+ usage(progname);
+ exit_nicely(0);
+
+ /* -? help or invalid option */
+ case '?':
+ if (is_help_param(argc, argv, optind))
+ {
+ usage(progname);
+ exit_nicely(0);
+ }
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+ exit_nicely(1);
+
default:
/* getopt_long already emitted a complaint */
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c
index a89d72fc5cf..82ac2addf03 100644
--- a/src/bin/pg_resetwal/pg_resetwal.c
+++ b/src/bin/pg_resetwal/pg_resetwal.c
@@ -89,7 +89,7 @@ static void KillExistingXLOG(void);
static void KillExistingArchiveStatus(void);
static void KillExistingWALSummaries(void);
static void WriteEmptyXLOG(void);
-static void usage(void);
+static void usage(const char *progname);
int
@@ -109,6 +109,8 @@ main(int argc, char *argv[])
{"next-transaction-id", required_argument, NULL, 'x'},
{"wal-segsize", required_argument, NULL, 1},
{"char-signedness", required_argument, NULL, 2},
+ {"version", no_argument, NULL, 'V'},
+ {"help", no_argument, NULL, 3},
{NULL, 0, NULL, 0}
};
@@ -126,22 +128,7 @@ main(int argc, char *argv[])
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_resetwal"));
progname = get_progname(argv[0]);
- if (argc > 1)
- {
- if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
- {
- usage();
- exit(0);
- }
- if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
- {
- puts("pg_resetwal (PostgreSQL) " PG_VERSION);
- exit(0);
- }
- }
-
-
- while ((c = getopt_long(argc, argv, "c:D:e:fl:m:no:O:u:x:", long_options, NULL)) != -1)
+ while ((c = getopt_long(argc, argv, "c:D:e:fl:m:no:O:u:Vx:?", long_options, NULL)) != -1)
{
switch (c)
{
@@ -293,6 +280,10 @@ main(int argc, char *argv[])
log_fname = pg_strdup(optarg);
break;
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
+ exit(0);
+
case 1:
{
int wal_segsize_mb;
@@ -322,6 +313,20 @@ main(int argc, char *argv[])
break;
}
+ case 3:
+ usage(progname);
+ exit(0);
+
+ /* -? help or invalid option */
+ case '?':
+ if (is_help_param(argc, argv, optind))
+ {
+ usage(progname);
+ exit(0);
+ }
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+ exit(1);
+
default:
/* getopt_long already emitted a complaint */
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
@@ -1171,7 +1176,7 @@ WriteEmptyXLOG(void)
static void
-usage(void)
+usage(const char *progname)
{
printf(_("%s resets the PostgreSQL write-ahead log.\n\n"), progname);
printf(_("Usage:\n"));
diff --git a/src/bin/pg_rewind/pg_rewind.c b/src/bin/pg_rewind/pg_rewind.c
index 0c68dd4235e..cc2fd37bf60 100644
--- a/src/bin/pg_rewind/pg_rewind.c
+++ b/src/bin/pg_rewind/pg_rewind.c
@@ -121,7 +121,8 @@ int
main(int argc, char **argv)
{
static struct option long_options[] = {
- {"help", no_argument, NULL, '?'},
+ {"help", no_argument, NULL, 7},
+ {"version", no_argument, NULL, 'V'},
{"target-pgdata", required_argument, NULL, 'D'},
{"write-recovery-conf", no_argument, NULL, 'R'},
{"source-pgdata", required_argument, NULL, 1},
@@ -158,22 +159,7 @@ main(int argc, char **argv)
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_rewind"));
progname = get_progname(argv[0]);
- /* Process command-line arguments */
- if (argc > 1)
- {
- if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
- {
- usage(progname);
- exit(0);
- }
- if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
- {
- puts("pg_rewind (PostgreSQL) " PG_VERSION);
- exit(0);
- }
- }
-
- while ((c = getopt_long(argc, argv, "cD:nNPR", long_options, &option_index)) != -1)
+ while ((c = getopt_long(argc, argv, "cD:nNPRV?", long_options, &option_index)) != -1)
{
switch (c)
{
@@ -227,6 +213,24 @@ main(int argc, char **argv)
exit(1);
break;
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
+ exit(0);
+
+ case 7:
+ usage(progname);
+ exit(0);
+
+ /* -? help or invalid option */
+ case '?':
+ if (is_help_param(argc, argv, optind))
+ {
+ usage(progname);
+ exit(0);
+ }
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+ exit(1);
+
default:
/* getopt_long already emitted a complaint */
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
diff --git a/src/bin/pg_test_fsync/pg_test_fsync.c b/src/bin/pg_test_fsync/pg_test_fsync.c
index 0060ea15902..85739bd88c4 100644
--- a/src/bin/pg_test_fsync/pg_test_fsync.c
+++ b/src/bin/pg_test_fsync/pg_test_fsync.c
@@ -142,12 +142,20 @@ main(int argc, char *argv[])
return 0;
}
+static void
+usage(const char *progname)
+{
+ printf(_("Usage: %s [-f FILENAME] [-s SECS-PER-TEST]\n"), progname);
+}
+
static void
handle_args(int argc, char *argv[])
{
static struct option long_options[] = {
{"filename", required_argument, NULL, 'f'},
{"secs-per-test", required_argument, NULL, 's'},
+ {"version", no_argument, NULL, 'V'},
+ {"help", no_argument, NULL, 1},
{NULL, 0, NULL, 0}
};
@@ -156,21 +164,7 @@ handle_args(int argc, char *argv[])
unsigned long optval; /* used for option parsing */
char *endptr;
- if (argc > 1)
- {
- if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
- {
- printf(_("Usage: %s [-f FILENAME] [-s SECS-PER-TEST]\n"), progname);
- exit(0);
- }
- if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
- {
- puts("pg_test_fsync (PostgreSQL) " PG_VERSION);
- exit(0);
- }
- }
-
- while ((option = getopt_long(argc, argv, "f:s:",
+ while ((option = getopt_long(argc, argv, "f:s:V?",
long_options, &optindex)) != -1)
{
switch (option)
@@ -197,6 +191,24 @@ handle_args(int argc, char *argv[])
"--secs-per-test", 1, UINT_MAX);
break;
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
+ exit(0);
+
+ case 1:
+ usage(progname);
+ exit(0);
+
+ /* -? help or invalid option */
+ case '?':
+ if (is_help_param(argc, argv, optind))
+ {
+ usage(progname);
+ exit(0);
+ }
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+ exit(1);
+
default:
/* getopt_long already emitted a complaint */
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
diff --git a/src/bin/pg_test_timing/pg_test_timing.c b/src/bin/pg_test_timing/pg_test_timing.c
index a5621251afc..25e44aa79f7 100644
--- a/src/bin/pg_test_timing/pg_test_timing.c
+++ b/src/bin/pg_test_timing/pg_test_timing.c
@@ -50,12 +50,20 @@ main(int argc, char *argv[])
return 0;
}
+static void
+usage(const char *progname)
+{
+ printf(_("Usage: %s [-d DURATION] [-c CUTOFF]\n"), progname);
+}
+
static void
handle_args(int argc, char *argv[])
{
static struct option long_options[] = {
{"duration", required_argument, NULL, 'd'},
{"cutoff", required_argument, NULL, 'c'},
+ {"version", no_argument, NULL, 'V'},
+ {"help", no_argument, NULL, 1},
{NULL, 0, NULL, 0}
};
@@ -64,21 +72,7 @@ handle_args(int argc, char *argv[])
unsigned long optval; /* used for option parsing */
char *endptr;
- if (argc > 1)
- {
- if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
- {
- printf(_("Usage: %s [-d DURATION] [-c CUTOFF]\n"), progname);
- exit(0);
- }
- if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
- {
- puts("pg_test_timing (PostgreSQL) " PG_VERSION);
- exit(0);
- }
- }
-
- while ((option = getopt_long(argc, argv, "d:c:",
+ while ((option = getopt_long(argc, argv, "d:c:V?",
long_options, &optindex)) != -1)
{
switch (option)
@@ -125,6 +119,25 @@ handle_args(int argc, char *argv[])
}
break;
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
+ exit(0);
+
+ case 1:
+ usage(progname);
+ exit(0);
+
+ /* -? help or invalid option */
+ case '?':
+ if (is_help_param(argc, argv, optind))
+ {
+ usage(progname);
+ exit(0);
+ }
+ fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
+ progname);
+ exit(1);
+
default:
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
diff --git a/src/bin/pg_upgrade/option.c b/src/bin/pg_upgrade/option.c
index 7fd7f1d33fc..557919e9d90 100644
--- a/src/bin/pg_upgrade/option.c
+++ b/src/bin/pg_upgrade/option.c
@@ -19,7 +19,7 @@
#include "pg_upgrade.h"
#include "utils/pidfile.h"
-static void usage(void);
+static void usage(const char *progname);
static void check_required_directory(char **dirpath,
const char *envVarName, bool useCwd,
const char *cmdLineOption, const char *description,
@@ -64,6 +64,9 @@ parseCommandLine(int argc, char *argv[])
{"set-char-signedness", required_argument, NULL, 6},
{"swap", no_argument, NULL, 7},
+ {"version", no_argument, NULL, 'V'},
+ {"help", no_argument, NULL, 8},
+
{NULL, 0, NULL, 0}
};
int option; /* Command line option */
@@ -91,25 +94,11 @@ parseCommandLine(int argc, char *argv[])
os_info.user = pg_strdup(getenv("PGUSER"));
}
- if (argc > 1)
- {
- if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
- {
- usage();
- exit(0);
- }
- if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
- {
- puts("pg_upgrade (PostgreSQL) " PG_VERSION);
- exit(0);
- }
- }
-
/* Allow help and version to be run as root, so do the test here. */
if (os_user_effective_id == 0)
pg_fatal("%s: cannot be run as root", os_info.progname);
- while ((option = getopt_long(argc, argv, "b:B:cd:D:j:kNo:O:p:P:rs:U:v",
+ while ((option = getopt_long(argc, argv, "b:B:cd:D:j:kNo:O:p:P:rs:U:vV?",
long_options, &optindex)) != -1)
{
switch (option)
@@ -200,6 +189,10 @@ parseCommandLine(int argc, char *argv[])
log_opts.verbose = true;
break;
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", os_info.progname);
+ exit(0);
+
case 1:
user_opts.transfer_mode = TRANSFER_MODE_CLONE;
break;
@@ -234,6 +227,21 @@ parseCommandLine(int argc, char *argv[])
user_opts.transfer_mode = TRANSFER_MODE_SWAP;
break;
+ case 8:
+ usage(os_info.progname);
+ exit(0);
+
+ /* -? help or invalid option */
+ case '?':
+ if (is_help_param(argc, argv, optind))
+ {
+ usage(os_info.progname);
+ exit(0);
+ }
+ fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
+ os_info.progname);
+ exit(1);
+
default:
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
os_info.progname);
@@ -301,11 +309,11 @@ parseCommandLine(int argc, char *argv[])
static void
-usage(void)
+usage(const char *progname)
{
- printf(_("pg_upgrade upgrades a PostgreSQL cluster to a different major version.\n\n"));
+ printf(_("%s upgrades a PostgreSQL cluster to a different major version.\n\n"), progname);
printf(_("Usage:\n"));
- printf(_(" pg_upgrade [OPTION]...\n\n"));
+ printf(_(" %s [OPTION]...\n\n"), progname);
printf(_("Options:\n"));
printf(_(" -b, --old-bindir=BINDIR old cluster executable directory\n"));
printf(_(" -B, --new-bindir=BINDIR new cluster executable directory (default\n"
diff --git a/src/bin/pg_verifybackup/pg_verifybackup.c b/src/bin/pg_verifybackup/pg_verifybackup.c
index 5e6c13bb921..0b68167ca82 100644
--- a/src/bin/pg_verifybackup/pg_verifybackup.c
+++ b/src/bin/pg_verifybackup/pg_verifybackup.c
@@ -100,9 +100,7 @@ static astreamer *create_archive_verifier(verifier_context *context,
pg_compress_algorithm compress_algo);
static void progress_report(bool finished);
-static void usage(void);
-
-static const char *progname;
+static void usage(const char *progname);
/* is progress reporting enabled? */
static bool show_progress = false;
@@ -127,6 +125,8 @@ main(int argc, char **argv)
{"quiet", no_argument, NULL, 'q'},
{"skip-checksums", no_argument, NULL, 's'},
{"wal-directory", required_argument, NULL, 'w'},
+ {"version", no_argument, NULL, 'V'},
+ {"help", no_argument, NULL, 1},
{NULL, 0, NULL, 0}
};
@@ -138,6 +138,7 @@ main(int argc, char **argv)
char *wal_directory = NULL;
char *pg_waldump_path = NULL;
DIR *dir;
+ const char *progname;
pg_logging_init(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_verifybackup"));
@@ -145,20 +146,6 @@ main(int argc, char **argv)
memset(&context, 0, sizeof(context));
- if (argc > 1)
- {
- if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
- {
- usage();
- exit(0);
- }
- if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
- {
- puts("pg_verifybackup (PostgreSQL) " PG_VERSION);
- exit(0);
- }
- }
-
/*
* Skip certain files in the toplevel directory.
*
@@ -180,7 +167,7 @@ main(int argc, char **argv)
simple_string_list_append(&context.ignore_list, "recovery.signal");
simple_string_list_append(&context.ignore_list, "standby.signal");
- while ((c = getopt_long(argc, argv, "eF:i:m:nPqsw:", long_options, NULL)) != -1)
+ while ((c = getopt_long(argc, argv, "eF:i:m:nPqsVw:?", long_options, NULL)) != -1)
{
switch (c)
{
@@ -220,10 +207,25 @@ main(int argc, char **argv)
case 's':
context.skip_checksums = true;
break;
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
+ exit(0);
case 'w':
wal_directory = pstrdup(optarg);
canonicalize_path(wal_directory);
break;
+ case 1:
+ usage(progname);
+ exit(0);
+ /* -? help or invalid option */
+ case '?':
+ if (is_help_param(argc, argv, optind))
+ {
+ usage(progname);
+ exit(0);
+ }
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+ exit(1);
default:
/* getopt_long already emitted a complaint */
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
@@ -1363,7 +1365,7 @@ progress_report(bool finished)
* Print out usage information and exit.
*/
static void
-usage(void)
+usage(const char *progname)
{
printf(_("%s verifies a backup against the backup manifest.\n\n"), progname);
printf(_("Usage:\n %s [OPTION]... BACKUPDIR\n\n"), progname);
diff --git a/src/bin/pg_waldump/pg_waldump.c b/src/bin/pg_waldump/pg_waldump.c
index 13d3ec2f5be..5159893b619 100644
--- a/src/bin/pg_waldump/pg_waldump.c
+++ b/src/bin/pg_waldump/pg_waldump.c
@@ -37,8 +37,6 @@
* give a thought about doing the same in pg_walinspect contrib module as well.
*/
-static const char *progname;
-
static int WalSegSz;
static volatile sig_atomic_t time_to_stop = false;
@@ -753,7 +751,7 @@ XLogDumpDisplayStats(XLogDumpConfig *config, XLogStats *stats)
}
static void
-usage(void)
+usage(const char *progname)
{
printf(_("%s decodes and displays PostgreSQL write-ahead logs for debugging.\n\n"),
progname);
@@ -809,7 +807,7 @@ main(int argc, char **argv)
{"follow", no_argument, NULL, 'f'},
{"fork", required_argument, NULL, 'F'},
{"fullpage", no_argument, NULL, 'w'},
- {"help", no_argument, NULL, '?'},
+ {"help", no_argument, NULL, 2},
{"limit", required_argument, NULL, 'n'},
{"path", required_argument, NULL, 'p'},
{"quiet", no_argument, NULL, 'q'},
@@ -826,7 +824,7 @@ main(int argc, char **argv)
int option;
int optindex = 0;
-
+ const char *progname;
#ifndef WIN32
pqsignal(SIGINT, sigint_handler);
#endif
@@ -835,20 +833,6 @@ main(int argc, char **argv)
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_waldump"));
progname = get_progname(argv[0]);
- if (argc > 1)
- {
- if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
- {
- usage();
- exit(0);
- }
- if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
- {
- puts("pg_waldump (PostgreSQL) " PG_VERSION);
- exit(0);
- }
- }
-
memset(&private, 0, sizeof(XLogDumpPrivate));
memset(&config, 0, sizeof(XLogDumpConfig));
memset(&stats, 0, sizeof(XLogStats));
@@ -885,7 +869,7 @@ main(int argc, char **argv)
goto bad_argument;
}
- while ((option = getopt_long(argc, argv, "bB:e:fF:n:p:qr:R:s:t:wx:z",
+ while ((option = getopt_long(argc, argv, "bB:e:fF:n:p:qr:R:s:t:Vwx:z?",
long_options, &optindex)) != -1)
{
switch (option)
@@ -1046,6 +1030,9 @@ main(int argc, char **argv)
break;
}
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
+ exit(0);
case 'w':
config.filter_by_fpw = true;
break;
@@ -1076,6 +1063,17 @@ main(int argc, char **argv)
case 1:
config.save_fullpage_path = pg_strdup(optarg);
break;
+ case 2:
+ usage(progname);
+ exit(0);
+ /* -? help or invalid option */
+ case '?':
+ if (is_help_param(argc, argv, optind))
+ {
+ usage(progname);
+ exit(0);
+ }
+ goto bad_argument;
default:
goto bad_argument;
}
diff --git a/src/bin/pg_walsummary/pg_walsummary.c b/src/bin/pg_walsummary/pg_walsummary.c
index cd7a6b147b2..ac39dddd724 100644
--- a/src/bin/pg_walsummary/pg_walsummary.c
+++ b/src/bin/pg_walsummary/pg_walsummary.c
@@ -18,7 +18,6 @@
#include "common/blkreftable.h"
#include "common/int.h"
#include "common/logging.h"
-#include "fe_utils/option_utils.h"
#include "getopt_long.h"
typedef struct ws_options
@@ -54,6 +53,8 @@ main(int argc, char *argv[])
static struct option long_options[] = {
{"individual", no_argument, NULL, 'i'},
{"quiet", no_argument, NULL, 'q'},
+ {"version", no_argument, NULL, 'V'},
+ {"help", no_argument, NULL, 1},
{NULL, 0, NULL, 0}
};
@@ -67,10 +68,9 @@ main(int argc, char *argv[])
pg_logging_init(argv[0]);
progname = get_progname(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_walsummary"));
- handle_help_version_opts(argc, argv, progname, help);
/* process command-line options */
- while ((c = getopt_long(argc, argv, "iq",
+ while ((c = getopt_long(argc, argv, "iqV?",
long_options, &optindex)) != -1)
{
switch (c)
@@ -81,6 +81,21 @@ main(int argc, char *argv[])
case 'q':
opt.quiet = true;
break;
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
+ exit(0);
+ case 1:
+ help(progname);
+ exit(0);
+ /* -? or invalid option */
+ case '?':
+ if (is_help_param(argc, argv, optind))
+ {
+ help(progname);
+ exit(0);
+ }
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+ exit(1);
default:
/* getopt_long already emitted a complaint */
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index 1515ed405ba..0c34a533499 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -894,7 +894,7 @@ pg_time_now_lazy(pg_time_usec_t *now)
#define PG_TIME_GET_DOUBLE(t) (0.000001 * (t))
static void
-usage(void)
+usage(const char *progname)
{
printf("%s is a benchmarking tool for PostgreSQL.\n\n"
"Usage:\n"
@@ -6739,6 +6739,8 @@ main(int argc, char **argv)
{"verbose-errors", no_argument, NULL, 15},
{"exit-on-abort", no_argument, NULL, 16},
{"debug", no_argument, NULL, 17},
+ {"version", no_argument, NULL, 'V'},
+ {"help", no_argument, NULL, 18},
{NULL, 0, NULL, 0}
};
@@ -6790,27 +6792,13 @@ main(int argc, char **argv)
pg_logging_init(argv[0]);
progname = get_progname(argv[0]);
- if (argc > 1)
- {
- if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
- {
- usage();
- exit(0);
- }
- if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
- {
- puts("pgbench (PostgreSQL) " PG_VERSION);
- exit(0);
- }
- }
-
state = (CState *) pg_malloc0(sizeof(CState));
/* set random seed early, because it may be used while parsing scripts. */
if (!set_random_seed(getenv("PGBENCH_RANDOM_SEED")))
pg_fatal("error while setting random seed from PGBENCH_RANDOM_SEED environment variable");
- while ((c = getopt_long(argc, argv, "b:c:Cd:D:f:F:h:iI:j:lL:M:nNp:P:qrR:s:St:T:U:v", long_options, &optindex)) != -1)
+ while ((c = getopt_long(argc, argv, "b:c:Cd:D:f:F:h:iI:j:lL:M:nNp:P:qrR:s:St:T:U:vV?", long_options, &optindex)) != -1)
{
char *script;
@@ -7001,6 +6989,9 @@ main(int argc, char **argv)
benchmarking_option_set = true;
do_vacuum_accounts = true;
break;
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
+ exit(0);
case 1: /* unlogged-tables */
initialization_option_set = true;
unlogged_tables = true;
@@ -7092,6 +7083,18 @@ main(int argc, char **argv)
case 17: /* debug */
pg_logging_increase_verbosity();
break;
+ case 18:
+ usage(progname);
+ exit(0);
+ /* -? or invalid option */
+ case '?':
+ if (is_help_param(argc, argv, optind))
+ {
+ usage(progname);
+ exit(0);
+ }
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+ exit(1);
default:
/* getopt_long already emitted a complaint */
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index 249b6aa5169..73046382c9b 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -135,20 +135,6 @@ main(int argc, char *argv[])
pg_logging_set_locus_callback(log_locus_callback);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("psql"));
- if (argc > 1)
- {
- if ((strcmp(argv[1], "-?") == 0) || (argc == 2 && (strcmp(argv[1], "--help") == 0)))
- {
- usage(NOPAGER);
- exit(EXIT_SUCCESS);
- }
- if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
- {
- showVersion();
- exit(EXIT_SUCCESS);
- }
- }
-
pset.progname = get_progname(argv[0]);
pset.db = NULL;
diff --git a/src/bin/scripts/clusterdb.c b/src/bin/scripts/clusterdb.c
index a0aa950b784..4107e6ff98c 100644
--- a/src/bin/scripts/clusterdb.c
+++ b/src/bin/scripts/clusterdb.c
@@ -13,7 +13,6 @@
#include "common.h"
#include "common/logging.h"
#include "fe_utils/cancel.h"
-#include "fe_utils/option_utils.h"
#include "fe_utils/query_utils.h"
#include "fe_utils/simple_list.h"
@@ -42,6 +41,8 @@ main(int argc, char *argv[])
{"table", required_argument, NULL, 't'},
{"verbose", no_argument, NULL, 'v'},
{"maintenance-db", required_argument, NULL, 2},
+ {"version", no_argument, NULL, 'V'},
+ {"help", no_argument, NULL, 3},
{NULL, 0, NULL, 0}
};
@@ -66,9 +67,7 @@ main(int argc, char *argv[])
progname = get_progname(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pgscripts"));
- handle_help_version_opts(argc, argv, "clusterdb", help);
-
- while ((c = getopt_long(argc, argv, "ad:eh:p:qt:U:vwW", long_options, &optindex)) != -1)
+ while ((c = getopt_long(argc, argv, "ad:eh:p:qt:U:vVwW?", long_options, &optindex)) != -1)
{
switch (c)
{
@@ -99,6 +98,9 @@ main(int argc, char *argv[])
case 'v':
verbose = true;
break;
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
+ exit(0);
case 'w':
prompt_password = TRI_NO;
break;
@@ -108,6 +110,18 @@ main(int argc, char *argv[])
case 2:
maintenance_db = pg_strdup(optarg);
break;
+ case 3:
+ help(progname);
+ exit(0);
+ /* -? help or invalid option */
+ case '?':
+ if (is_help_param(argc, argv, optind))
+ {
+ help(progname);
+ exit(0);
+ }
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+ exit(1);
default:
/* getopt_long already emitted a complaint */
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
diff --git a/src/bin/scripts/createdb.c b/src/bin/scripts/createdb.c
index 7c0cf32d6a1..6fbbf491dfd 100644
--- a/src/bin/scripts/createdb.c
+++ b/src/bin/scripts/createdb.c
@@ -13,7 +13,6 @@
#include "common.h"
#include "common/logging.h"
-#include "fe_utils/option_utils.h"
#include "fe_utils/string_utils.h"
@@ -43,6 +42,8 @@ main(int argc, char *argv[])
{"builtin-locale", required_argument, NULL, 5},
{"icu-locale", required_argument, NULL, 6},
{"icu-rules", required_argument, NULL, 7},
+ {"version", no_argument, NULL, 'V'},
+ {"help", no_argument, NULL, 8},
{NULL, 0, NULL, 0}
};
@@ -81,9 +82,7 @@ main(int argc, char *argv[])
progname = get_progname(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pgscripts"));
- handle_help_version_opts(argc, argv, "createdb", help);
-
- while ((c = getopt_long(argc, argv, "D:eE:h:l:O:p:S:T:U:wW", long_options, &optindex)) != -1)
+ while ((c = getopt_long(argc, argv, "D:eE:h:l:O:p:S:T:U:VwW?", long_options, &optindex)) != -1)
{
switch (c)
{
@@ -117,6 +116,9 @@ main(int argc, char *argv[])
case 'U':
username = pg_strdup(optarg);
break;
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
+ exit(0);
case 'w':
prompt_password = TRI_NO;
break;
@@ -144,6 +146,18 @@ main(int argc, char *argv[])
case 7:
icu_rules = pg_strdup(optarg);
break;
+ case 8:
+ help(progname);
+ exit(0);
+ /* -? help or invalid option */
+ case '?':
+ if (is_help_param(argc, argv, optind))
+ {
+ help(progname);
+ exit(0);
+ }
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+ exit(1);
default:
/* getopt_long already emitted a complaint */
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
diff --git a/src/bin/scripts/createuser.c b/src/bin/scripts/createuser.c
index 81e6abfc46e..44fa1785be5 100644
--- a/src/bin/scripts/createuser.c
+++ b/src/bin/scripts/createuser.c
@@ -57,6 +57,8 @@ main(int argc, char *argv[])
{"interactive", no_argument, NULL, 3},
{"bypassrls", no_argument, NULL, 4},
{"no-bypassrls", no_argument, NULL, 5},
+ {"version", no_argument, NULL, 'V'},
+ {"help", no_argument, NULL, 6},
{NULL, 0, NULL, 0}
};
@@ -97,9 +99,7 @@ main(int argc, char *argv[])
progname = get_progname(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pgscripts"));
- handle_help_version_opts(argc, argv, "createuser", help);
-
- while ((c = getopt_long(argc, argv, "a:c:dDeEg:h:iIlLm:p:PrRsSU:v:wW",
+ while ((c = getopt_long(argc, argv, "a:c:dDeEg:h:iIlLm:p:PrRsSU:v:VwW?",
long_options, &optindex)) != -1)
{
switch (c)
@@ -169,6 +169,9 @@ main(int argc, char *argv[])
case 'v':
pwexpiry = pg_strdup(optarg);
break;
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
+ exit(0);
case 'w':
prompt_password = TRI_NO;
break;
@@ -190,6 +193,18 @@ main(int argc, char *argv[])
case 5:
bypassrls = TRI_NO;
break;
+ case 6:
+ help(progname);
+ exit(0);
+ /* -? help or invalid option */
+ case '?':
+ if (is_help_param(argc, argv, optind))
+ {
+ help(progname);
+ exit(0);
+ }
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+ exit(1);
default:
/* getopt_long already emitted a complaint */
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
diff --git a/src/bin/scripts/dropdb.c b/src/bin/scripts/dropdb.c
index 0b630818277..9ab2d170ff9 100644
--- a/src/bin/scripts/dropdb.c
+++ b/src/bin/scripts/dropdb.c
@@ -13,7 +13,6 @@
#include "postgres_fe.h"
#include "common.h"
#include "common/logging.h"
-#include "fe_utils/option_utils.h"
#include "fe_utils/string_utils.h"
@@ -36,6 +35,8 @@ main(int argc, char *argv[])
{"if-exists", no_argument, &if_exists, 1},
{"maintenance-db", required_argument, NULL, 2},
{"force", no_argument, NULL, 'f'},
+ {"version", no_argument, NULL, 'V'},
+ {"help", no_argument, NULL, 3},
{NULL, 0, NULL, 0}
};
@@ -63,9 +64,7 @@ main(int argc, char *argv[])
progname = get_progname(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pgscripts"));
- handle_help_version_opts(argc, argv, "dropdb", help);
-
- while ((c = getopt_long(argc, argv, "efh:ip:U:wW", long_options, &optindex)) != -1)
+ while ((c = getopt_long(argc, argv, "efh:ip:U:wWV?", long_options, &optindex)) != -1)
{
switch (c)
{
@@ -87,6 +86,9 @@ main(int argc, char *argv[])
case 'U':
username = pg_strdup(optarg);
break;
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
+ exit(0);
case 'w':
prompt_password = TRI_NO;
break;
@@ -99,6 +101,18 @@ main(int argc, char *argv[])
case 2:
maintenance_db = pg_strdup(optarg);
break;
+ case 3:
+ help(progname);
+ exit(0);
+ /* -? help or invalid option */
+ case '?':
+ if (is_help_param(argc, argv, optind))
+ {
+ help(progname);
+ exit(0);
+ }
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+ exit(1);
default:
/* getopt_long already emitted a complaint */
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
diff --git a/src/bin/scripts/dropuser.c b/src/bin/scripts/dropuser.c
index 39bb1686173..d55d5a34aa3 100644
--- a/src/bin/scripts/dropuser.c
+++ b/src/bin/scripts/dropuser.c
@@ -14,7 +14,6 @@
#include "common.h"
#include "common/logging.h"
#include "common/string.h"
-#include "fe_utils/option_utils.h"
#include "fe_utils/string_utils.h"
@@ -35,6 +34,8 @@ main(int argc, char *argv[])
{"echo", no_argument, NULL, 'e'},
{"interactive", no_argument, NULL, 'i'},
{"if-exists", no_argument, &if_exists, 1},
+ {"version", no_argument, NULL, 'V'},
+ {"help", no_argument, NULL, 2},
{NULL, 0, NULL, 0}
};
@@ -60,9 +61,7 @@ main(int argc, char *argv[])
progname = get_progname(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pgscripts"));
- handle_help_version_opts(argc, argv, "dropuser", help);
-
- while ((c = getopt_long(argc, argv, "eh:ip:U:wW", long_options, &optindex)) != -1)
+ while ((c = getopt_long(argc, argv, "eh:ip:U:VwW?", long_options, &optindex)) != -1)
{
switch (c)
{
@@ -81,6 +80,9 @@ main(int argc, char *argv[])
case 'U':
username = pg_strdup(optarg);
break;
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
+ exit(0);
case 'w':
prompt_password = TRI_NO;
break;
@@ -90,6 +92,18 @@ main(int argc, char *argv[])
case 0:
/* this covers the long options */
break;
+ case 2:
+ help(progname);
+ exit(0);
+ /* -? help or invalid option */
+ case '?':
+ if (is_help_param(argc, argv, optind))
+ {
+ help(progname);
+ exit(0);
+ }
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+ exit(1);
default:
/* getopt_long already emitted a complaint */
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
diff --git a/src/bin/scripts/pg_isready.c b/src/bin/scripts/pg_isready.c
index 7b4ea3f39a9..031c84a05c9 100644
--- a/src/bin/scripts/pg_isready.c
+++ b/src/bin/scripts/pg_isready.c
@@ -12,7 +12,6 @@
#include "postgres_fe.h"
#include "common.h"
#include "common/logging.h"
-#include "fe_utils/option_utils.h"
#define DEFAULT_CONNECT_TIMEOUT "3"
@@ -62,15 +61,16 @@ main(int argc, char **argv)
{"quiet", no_argument, NULL, 'q'},
{"timeout", required_argument, NULL, 't'},
{"username", required_argument, NULL, 'U'},
+ {"version", no_argument, NULL, 'V'},
+ {"help", no_argument, NULL, 1},
{NULL, 0, NULL, 0}
};
pg_logging_init(argv[0]);
progname = get_progname(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pgscripts"));
- handle_help_version_opts(argc, argv, progname, help);
- while ((c = getopt_long(argc, argv, "d:h:p:qt:U:", long_options, NULL)) != -1)
+ while ((c = getopt_long(argc, argv, "d:h:p:qt:U:V?", long_options, NULL)) != -1)
{
switch (c)
{
@@ -92,6 +92,21 @@ main(int argc, char **argv)
case 'U':
pguser = pg_strdup(optarg);
break;
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
+ exit(0);
+ case 1:
+ help(progname);
+ exit(0);
+ /* -? help or invalid option */
+ case '?':
+ if (is_help_param(argc, argv, optind))
+ {
+ help(progname);
+ exit(0);
+ }
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+ exit(PQPING_NO_ATTEMPT);
default:
/* getopt_long already emitted a complaint */
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
diff --git a/src/bin/scripts/reindexdb.c b/src/bin/scripts/reindexdb.c
index 8ddcc5312f7..a2e28165def 100644
--- a/src/bin/scripts/reindexdb.c
+++ b/src/bin/scripts/reindexdb.c
@@ -86,6 +86,8 @@ main(int argc, char *argv[])
{"concurrently", no_argument, NULL, 1},
{"maintenance-db", required_argument, NULL, 2},
{"tablespace", required_argument, NULL, 3},
+ {"version", no_argument, NULL, 'V'},
+ {"help", no_argument, NULL, 4},
{NULL, 0, NULL, 0}
};
@@ -116,10 +118,8 @@ main(int argc, char *argv[])
progname = get_progname(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pgscripts"));
- handle_help_version_opts(argc, argv, "reindexdb", help);
-
/* process command-line options */
- while ((c = getopt_long(argc, argv, "ad:eh:i:j:qp:sS:t:U:vwW", long_options, &optindex)) != -1)
+ while ((c = getopt_long(argc, argv, "ad:eh:i:j:qp:sS:t:U:vVwW?", long_options, &optindex)) != -1)
{
switch (c)
{
@@ -164,6 +164,9 @@ main(int argc, char *argv[])
case 'v':
verbose = true;
break;
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
+ exit(0);
case 'w':
prompt_password = TRI_NO;
break;
@@ -179,6 +182,18 @@ main(int argc, char *argv[])
case 3:
tablespace = pg_strdup(optarg);
break;
+ case 4:
+ help(progname);
+ exit(0);
+ /* -? help or invalid option */
+ case '?':
+ if (is_help_param(argc, argv, optind))
+ {
+ help(progname);
+ exit(0);
+ }
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+ exit(1);
default:
/* getopt_long already emitted a complaint */
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c
index e117dac2242..ccc896e7046 100644
--- a/src/bin/scripts/vacuumdb.c
+++ b/src/bin/scripts/vacuumdb.c
@@ -59,6 +59,8 @@ main(int argc, char *argv[])
{"no-process-main", no_argument, NULL, 12},
{"buffer-usage-limit", required_argument, NULL, 13},
{"missing-stats-only", no_argument, NULL, 14},
+ {"version", no_argument, NULL, 'V'},
+ {"help", no_argument, NULL, 15},
{NULL, 0, NULL, 0}
};
@@ -95,10 +97,7 @@ main(int argc, char *argv[])
progname = get_progname(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pgscripts"));
- handle_help_version_opts(argc, argv, "vacuumdb", help);
-
- while ((c = getopt_long(argc, argv, "ad:efFh:j:n:N:p:P:qt:U:vwWzZ",
- long_options, &optindex)) != -1)
+ while ((c = getopt_long(argc, argv, "ad:efFh:j:n:N:p:P:qt:U:vVwWzZ?", long_options, &optindex)) != -1)
{
switch (c)
{
@@ -156,6 +155,9 @@ main(int argc, char *argv[])
case 'v':
vacopts.verbose = true;
break;
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
+ exit(0);
case 'w':
cparams.prompt_password = TRI_NO;
break;
@@ -213,6 +215,18 @@ main(int argc, char *argv[])
case 14:
vacopts.missing_stats_only = true;
break;
+ case 15:
+ help(progname);
+ exit(0);
+ /* -? help or invalid option */
+ case '?':
+ if (is_help_param(argc, argv, optind))
+ {
+ help(progname);
+ exit(0);
+ }
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+ exit(1);
default:
/* getopt_long already emitted a complaint */
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
diff --git a/src/bin/scripts/vacuuming.c b/src/bin/scripts/vacuuming.c
index f836f21fb03..947fca5bfe4 100644
--- a/src/bin/scripts/vacuuming.c
+++ b/src/bin/scripts/vacuuming.c
@@ -17,7 +17,6 @@
#include "common/connect.h"
#include "common/logging.h"
#include "fe_utils/cancel.h"
-#include "fe_utils/option_utils.h"
#include "fe_utils/parallel_slot.h"
#include "fe_utils/query_utils.h"
#include "fe_utils/string_utils.h"
diff --git a/src/fe_utils/option_utils.c b/src/fe_utils/option_utils.c
index 6cb4ac7ffeb..12cbe1ef830 100644
--- a/src/fe_utils/option_utils.c
+++ b/src/fe_utils/option_utils.c
@@ -16,27 +16,22 @@
#include "common/string.h"
#include "fe_utils/option_utils.h"
+
/*
- * Provide strictly harmonized handling of --help and --version
- * options.
+ * is_help_param
+ *
+ * getopt_long returns '?' for any invalid parameters as well as for the help
+ * parameter '-?' without any way to distinguish the two cases. This helper
+ * function can be used to inspect the current parameter in argv in order to
+ * determine which case it was.
*/
-void
-handle_help_version_opts(int argc, char *argv[],
- const char *fixed_progname, help_handler hlp)
+bool
+is_help_param(int argc, char *argv[], int optind)
{
- if (argc > 1)
- {
- if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
- {
- hlp(get_progname(argv[0]));
- exit(0);
- }
- if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
- {
- printf("%s (PostgreSQL) " PG_VERSION "\n", fixed_progname);
- exit(0);
- }
- }
+ if (argc > 1 && optind <= argc && strcmp(argv[optind - 1], "-?") == 0)
+ return true;
+
+ return false;
}
/*
diff --git a/src/include/fe_utils/option_utils.h b/src/include/fe_utils/option_utils.h
index 4504bbb36a8..d8fd0ba8c0d 100644
--- a/src/include/fe_utils/option_utils.h
+++ b/src/include/fe_utils/option_utils.h
@@ -14,11 +14,6 @@
#include "common/file_utils.h"
-typedef void (*help_handler) (const char *progname);
-
-extern void handle_help_version_opts(int argc, char *argv[],
- const char *fixed_progname,
- help_handler hlp);
extern bool option_parse_int(const char *optarg, const char *optname,
int min_range, int max_range,
int *result);
diff --git a/src/include/port.h b/src/include/port.h
index 3964d3b1293..152eb4991ad 100644
--- a/src/include/port.h
+++ b/src/include/port.h
@@ -562,4 +562,7 @@ extern int wait_result_to_exit_code(int exit_status);
#define HAVE_SYMLINK 1
#endif
+/* port/pg_option_utils.c */
+extern bool is_help_param(int argc, char *argv[], int optind);
+
#endif /* PG_PORT_H */
diff --git a/src/interfaces/ecpg/preproc/ecpg.c b/src/interfaces/ecpg/preproc/ecpg.c
index 3f0f10e654a..5e0143fedb5 100644
--- a/src/interfaces/ecpg/preproc/ecpg.c
+++ b/src/interfaces/ecpg/preproc/ecpg.c
@@ -126,11 +126,14 @@ add_preprocessor_define(char *define)
}
#define ECPG_GETOPT_LONG_REGRESSION 1
+#define ECPG_GETOPT_LONG_HELP 2
int
main(int argc, char *const argv[])
{
static struct option ecpg_options[] = {
{"regression", no_argument, NULL, ECPG_GETOPT_LONG_REGRESSION},
+ {"version", no_argument, NULL, 'V'},
+ {"help", no_argument, NULL, ECPG_GETOPT_LONG_HELP},
{NULL, 0, NULL, 0}
};
@@ -153,22 +156,8 @@ main(int argc, char *const argv[])
return ILLEGAL_OPTION;
}
- if (argc > 1)
- {
- if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
- {
- help(progname);
- exit(0);
- }
- if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
- {
- printf("ecpg (PostgreSQL) %s\n", PG_VERSION);
- exit(0);
- }
- }
-
output_filename = NULL;
- while ((c = getopt_long(argc, argv, "cC:dD:hiI:o:r:tv", ecpg_options, NULL)) != -1)
+ while ((c = getopt_long(argc, argv, "cC:dD:hiI:o:r:tvV?", ecpg_options, NULL)) != -1)
{
switch (c)
{
@@ -256,8 +245,23 @@ main(int argc, char *const argv[])
case ECPG_GETOPT_LONG_REGRESSION:
regression_mode = true;
break;
+ case 'V':
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
+ exit(0);
+ case ECPG_GETOPT_LONG_HELP:
+ help(progname);
+ exit(0);
+ /* -? help or invalid option */
+ case '?':
+ if (is_help_param(argc, (char **) argv, optind))
+ {
+ help(progname);
+ exit(0);
+ }
+ fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
+ exit(1);
default:
- fprintf(stderr, _("Try \"%s --help\" for more information.\n"), argv[0]);
+ fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
return ILLEGAL_OPTION;
}
}
@@ -283,7 +287,7 @@ main(int argc, char *const argv[])
if (optind >= argc) /* no files specified */
{
fprintf(stderr, _("%s: no input files specified\n"), progname);
- fprintf(stderr, _("Try \"%s --help\" for more information.\n"), argv[0]);
+ fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
return ILLEGAL_OPTION;
}
else
diff --git a/src/port/Makefile b/src/port/Makefile
index 4274949dfa4..a4376b954b7 100644
--- a/src/port/Makefile
+++ b/src/port/Makefile
@@ -46,6 +46,7 @@ OBJS = \
pg_bitutils.o \
pg_localeconv_r.o \
pg_numa.o \
+ pg_option_utils.o \
pg_popcount_aarch64.o \
pg_popcount_avx512.o \
pg_strong_random.o \
diff --git a/src/port/meson.build b/src/port/meson.build
index fc7b059fee5..0a81144f713 100644
--- a/src/port/meson.build
+++ b/src/port/meson.build
@@ -9,6 +9,7 @@ pgport_sources = [
'pg_bitutils.c',
'pg_localeconv_r.c',
'pg_numa.c',
+ 'pg_option_utils.c',
'pg_popcount_aarch64.c',
'pg_popcount_avx512.c',
'pg_strong_random.c',
diff --git a/src/port/pg_option_utils.c b/src/port/pg_option_utils.c
new file mode 100644
index 00000000000..b24f3bb28e9
--- /dev/null
+++ b/src/port/pg_option_utils.c
@@ -0,0 +1,30 @@
+/*-------------------------------------------------------------------------
+ *
+ * Command line option processing facilities
+ *
+ * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * src/port/pg_option_utils.c
+ *
+ *-------------------------------------------------------------------------
+ */
+
+#include "c.h"
+
+/*
+ * is_help_param
+ *
+ * getopt_long returns '?' for any invalid parameters as well as for the help
+ * parameter '-?' without any way to distinguish the two cases. This helper
+ * function can be used to inspect the current parameter in argv in order to
+ * determine which case it was.
+ */
+bool
+is_help_param(int argc, char *argv[], int optind)
+{
+ if (argc > 1 && optind <= argc && strcmp(argv[optind - 1], "-?") == 0)
+ return true;
+
+ return false;
+}
diff --git a/src/test/regress/pg_regress.c b/src/test/regress/pg_regress.c
index efc41fca2ba..fc32075bcad 100644
--- a/src/test/regress/pg_regress.c
+++ b/src/test/regress/pg_regress.c
@@ -2105,6 +2105,7 @@ regression_main(int argc, char *argv[],
int i;
int option_index;
char buf[MAXPGPATH * 4];
+ const char *progname;
pg_logging_init(argv[0]);
progname = get_progname(argv[0]);
@@ -2145,7 +2146,7 @@ regression_main(int argc, char *argv[],
help();
exit(0);
case 'V':
- puts("pg_regress (PostgreSQL) " PG_VERSION);
+ printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
exit(0);
case 1:
--
2.39.3 (Apple Git-146)
=
[application/octet-stream] v1-0002-Consistently-use-exit-code-1-for-invalid-argument.patch (1019B, ../../B8FA8D64-5575-41F1-9F3B-DF603495309A@yesql.se/3-v1-0002-Consistently-use-exit-code-1-for-invalid-argument.patch)
download | inline diff:
From 2d658d79e54de47d04f22d5128e0081b56cf9cc0 Mon Sep 17 00:00:00 2001
From: Daniel Gustafsson <dgustafsson@postgresql.org>
Date: Thu, 18 Sep 2025 15:04:28 +0200
Subject: [PATCH v1 2/2] Consistently use exit code 1 for invalid argument
When terminating an application due to an invalid command-line
argument we always use exit code 1.
Author: Daniel Gustafsson <daniel@yesql.se>
Reviewed-by: ..
Discussion: ..
---
src/bin/pg_archivecleanup/pg_archivecleanup.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/bin/pg_archivecleanup/pg_archivecleanup.c b/src/bin/pg_archivecleanup/pg_archivecleanup.c
index 700c06a3f44..328fa028876 100644
--- a/src/bin/pg_archivecleanup/pg_archivecleanup.c
+++ b/src/bin/pg_archivecleanup/pg_archivecleanup.c
@@ -336,7 +336,7 @@ main(int argc, char **argv)
default:
/* getopt already emitted a complaint */
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
- exit(2);
+ exit(1);
}
}
--
2.39.3 (Apple Git-146)
=
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: BUG #19042: Option --help not recognized at the end of command line in pg_restore
@ 2025-10-27 14:30 Nathan Bossart <nathandbossart@gmail.com>
parent: Daniel Gustafsson <daniel@yesql.se>
1 sibling, 1 reply; 20+ messages in thread
From: Nathan Bossart @ 2025-10-27 14:30 UTC (permalink / raw)
To: Daniel Gustafsson <daniel@yesql.se>; +Cc: Peter Eisentraut <peter@eisentraut.org>; Andres Freund <andres@anarazel.de>; Tom Lane <tgl@sss.pgh.pa.us>; Matthias Hörmann <matthias.hoermann@saltation.com>; pgsql-bugs@lists.postgresql.org
On Sat, Oct 25, 2025 at 12:26:01AM +0200, Daniel Gustafsson wrote:
> While hacking on this it seemed like a good idea to move to using progname
> consistently, and reduce scope in some places from global variables, but
> looking at it now I'm less convinced. At the very least it should be ripped
> out into its own patch but for now those changes are left in there.
Yeah, that does feel like it ought to be its own patch. After a
read-through, 0001 looks like the right idea to me, though. It's a larger
patch, but the majority of the changes are pretty mechanical.
+/* port/pg_option_utils.c */
+extern bool is_help_param(int argc, char *argv[], int optind);
And fe_utils/option_utils.c, right (since it has a copy of this function)?
Or is the idea to use pg_option_utils.c for both the frontend and the
backend?
> It's far from an exciting patchset but it would be nice to get it done once and
> for all. 0002 is a small change to make sure all apps exit with the same code,
> I was unable to find a documented rationale for exit(2) so I think it's an
> oversight.
0002 LGTM
--
nathan
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: BUG #19042: Option --help not recognized at the end of command line in pg_restore
@ 2025-10-27 19:49 Daniel Gustafsson <daniel@yesql.se>
parent: Nathan Bossart <nathandbossart@gmail.com>
0 siblings, 1 reply; 20+ messages in thread
From: Daniel Gustafsson @ 2025-10-27 19:49 UTC (permalink / raw)
To: Nathan Bossart <nathandbossart@gmail.com>; +Cc: Peter Eisentraut <peter@eisentraut.org>; Andres Freund <andres@anarazel.de>; Tom Lane <tgl@sss.pgh.pa.us>; Matthias Hörmann <matthias.hoermann@saltation.com>; pgsql-bugs@lists.postgresql.org
> On 27 Oct 2025, at 16:30, Nathan Bossart <nathandbossart@gmail.com> wrote:
Thanks for review!
> On Sat, Oct 25, 2025 at 12:26:01AM +0200, Daniel Gustafsson wrote:
>> While hacking on this it seemed like a good idea to move to using progname
>> consistently, and reduce scope in some places from global variables, but
>> looking at it now I'm less convinced. At the very least it should be ripped
>> out into its own patch but for now those changes are left in there.
>
> Yeah, that does feel like it ought to be its own patch.
Absolutely agree, will move that out in the next version.
> After a
> read-through, 0001 looks like the right idea to me, though. It's a larger
> patch, but the majority of the changes are pretty mechanical.
It’s indeed pretty boring, and considering what the patch want to achieve I guess that’s a good thing.
> +/* port/pg_option_utils.c */
> +extern bool is_help_param(int argc, char *argv[], int optind);
>
> And fe_utils/option_utils.c, right (since it has a copy of this function)?
> Or is the idea to use pg_option_utils.c for both the frontend and the
> backend?
I originally placed it in fe_utils but then moved to src/port to avoid adding libpq depesencies where we dont have them today. If there is a second copy then I missed that in my rebase (am travelling without laptop so cant comfortably read patches right now to check). Not sure what the best option is and how big of a deal it is. Do you have any suggestions?
./daniel
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: BUG #19042: Option --help not recognized at the end of command line in pg_restore
@ 2025-10-27 21:21 Nathan Bossart <nathandbossart@gmail.com>
parent: Daniel Gustafsson <daniel@yesql.se>
0 siblings, 0 replies; 20+ messages in thread
From: Nathan Bossart @ 2025-10-27 21:21 UTC (permalink / raw)
To: Daniel Gustafsson <daniel@yesql.se>; +Cc: Peter Eisentraut <peter@eisentraut.org>; Andres Freund <andres@anarazel.de>; Tom Lane <tgl@sss.pgh.pa.us>; Matthias Hörmann <matthias.hoermann@saltation.com>; pgsql-bugs@lists.postgresql.org
On Mon, Oct 27, 2025 at 09:49:06PM +0200, Daniel Gustafsson wrote:
> I originally placed it in fe_utils but then moved to src/port to avoid
> adding libpq depesencies where we dont have them today. If there is a
> second copy then I missed that in my rebase (am travelling without laptop
> so cant comfortably read patches right now to check). Not sure what the
> best option is and how big of a deal it is. Do you have any suggestions?
Oh. Unless my eyes deceive me, I think you forgot to remove the fe_utils
one.
--
nathan
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: BUG #19042: Option --help not recognized at the end of command line in pg_restore
@ 2025-10-29 15:24 Peter Eisentraut <peter@eisentraut.org>
parent: Daniel Gustafsson <daniel@yesql.se>
1 sibling, 1 reply; 20+ messages in thread
From: Peter Eisentraut @ 2025-10-29 15:24 UTC (permalink / raw)
To: Daniel Gustafsson <daniel@yesql.se>; Nathan Bossart <nathandbossart@gmail.com>; +Cc: Andres Freund <andres@anarazel.de>; Tom Lane <tgl@sss.pgh.pa.us>; Matthias Hörmann <matthias.hoermann@saltation.com>; pgsql-bugs@lists.postgresql.org
On 25.10.25 00:26, Daniel Gustafsson wrote:
> While hacking on this it seemed like a good idea to move to using progname
> consistently, and reduce scope in some places from global variables, but
> looking at it now I'm less convinced. At the very least it should be ripped
> out into its own patch but for now those changes are left in there.
The --version outputs intentionally do not use progname, so that you get
a proper identification of the program and version independent of what
the binary might be called. Please don't change that.
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: BUG #19042: Option --help not recognized at the end of command line in pg_restore
@ 2025-10-29 15:48 Tom Lane <tgl@sss.pgh.pa.us>
parent: Peter Eisentraut <peter@eisentraut.org>
0 siblings, 1 reply; 20+ messages in thread
From: Tom Lane @ 2025-10-29 15:48 UTC (permalink / raw)
To: Peter Eisentraut <peter@eisentraut.org>; +Cc: Daniel Gustafsson <daniel@yesql.se>; Nathan Bossart <nathandbossart@gmail.com>; Andres Freund <andres@anarazel.de>; Matthias Hörmann <matthias.hoermann@saltation.com>; pgsql-bugs@lists.postgresql.org
Peter Eisentraut <peter@eisentraut.org> writes:
> On 25.10.25 00:26, Daniel Gustafsson wrote:
>> While hacking on this it seemed like a good idea to move to using progname
>> consistently, and reduce scope in some places from global variables, but
>> looking at it now I'm less convinced. At the very least it should be ripped
>> out into its own patch but for now those changes are left in there.
> The --version outputs intentionally do not use progname, so that you get
> a proper identification of the program and version independent of what
> the binary might be called. Please don't change that.
Hmm, that's important institutional knowledge that should be captured
somewhere.
regards, tom lane
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: BUG #19042: Option --help not recognized at the end of command line in pg_restore
@ 2025-10-29 20:19 Daniel Gustafsson <daniel@yesql.se>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 20+ messages in thread
From: Daniel Gustafsson @ 2025-10-29 20:19 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Peter Eisentraut <peter@eisentraut.org>; Nathan Bossart <nathandbossart@gmail.com>; Andres Freund <andres@anarazel.de>; Matthias Hörmann <matthias.hoermann@saltation.com>; pgsql-bugs@lists.postgresql.org
> On 29 Oct 2025, at 17:54, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> Peter Eisentraut <peter@eisentraut.org> writes:
>>> On 25.10.25 00:26, Daniel Gustafsson wrote:
>>> While hacking on this it seemed like a good idea to move to using progname
>>> consistently, and reduce scope in some places from global variables, but
>>> looking at it now I'm less convinced. At the very least it should be ripped
>>> out into its own patch but for now those changes are left in there.
>
>> The --version outputs intentionally do not use progname, so that you get
>> a proper identification of the program and version independent of what
>> the binary might be called. Please don't change that.
All callsites using handle_help_version_opts were already using progname for —version, this just made it consistent. That being said, I can change it to be consistent in the other direction.
> Hmm, that's important institutional knowledge that should be captured
> somewhere.
Maybe a README in src/bin?
./daniel
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: BUG #19042: Option --help not recognized at the end of command line in pg_restore
@ 2025-11-03 20:57 Peter Eisentraut <peter@eisentraut.org>
parent: Daniel Gustafsson <daniel@yesql.se>
0 siblings, 0 replies; 20+ messages in thread
From: Peter Eisentraut @ 2025-11-03 20:57 UTC (permalink / raw)
To: Daniel Gustafsson <daniel@yesql.se>; Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Nathan Bossart <nathandbossart@gmail.com>; Andres Freund <andres@anarazel.de>; Matthias Hörmann <matthias.hoermann@saltation.com>; pgsql-bugs@lists.postgresql.org
On 29.10.25 21:19, Daniel Gustafsson wrote:
>
>
>> On 29 Oct 2025, at 17:54, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>>
>> Peter Eisentraut <peter@eisentraut.org> writes:
>>>> On 25.10.25 00:26, Daniel Gustafsson wrote:
>>>> While hacking on this it seemed like a good idea to move to using progname
>>>> consistently, and reduce scope in some places from global variables, but
>>>> looking at it now I'm less convinced. At the very least it should be ripped
>>>> out into its own patch but for now those changes are left in there.
>>
>>> The --version outputs intentionally do not use progname, so that you get
>>> a proper identification of the program and version independent of what
>>> the binary might be called. Please don't change that.
>
> All callsites using handle_help_version_opts were already using progname for —version, this just made it consistent. That being said, I can change it to be consistent in the other direction.
AFAICT, handle_help_version_opts() does this correctly: It takes an
argument fixed_progname that is used for --version output, while for the
--help output it uses argv. And most callers provide a fixed string for
fixed_progname, but I see that some don't.
>> Hmm, that's important institutional knowledge that should be captured
>> somewhere.
>
> Maybe a README in src/bin?
Maybe just a better code comment at handle_help_version_opts().
^ permalink raw reply [nested|flat] 20+ messages in thread
end of thread, other threads:[~2025-11-03 20:57 UTC | newest]
Thread overview: 20+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-09-03 11:07 BUG #19042: Option --help not recognized at the end of command line in pg_restore PG Bug reporting form <noreply@postgresql.org>
2025-09-03 11:45 ` Daniel Gustafsson <daniel@yesql.se>
2025-09-03 11:48 ` Matthias Hörmann <matthias.hoermann@saltation.com>
2025-09-03 14:57 ` Tom Lane <tgl@sss.pgh.pa.us>
2025-09-03 19:09 ` Daniel Gustafsson <daniel@yesql.se>
2025-09-03 19:22 ` Tom Lane <tgl@sss.pgh.pa.us>
2025-09-03 19:34 ` Andres Freund <andres@anarazel.de>
2025-09-10 05:26 ` Peter Eisentraut <peter@eisentraut.org>
2025-09-10 09:24 ` Daniel Gustafsson <daniel@yesql.se>
2025-10-22 21:23 ` Nathan Bossart <nathandbossart@gmail.com>
2025-10-22 21:53 ` Daniel Gustafsson <daniel@yesql.se>
2025-10-24 22:26 ` Daniel Gustafsson <daniel@yesql.se>
2025-10-27 14:30 ` Nathan Bossart <nathandbossart@gmail.com>
2025-10-27 19:49 ` Daniel Gustafsson <daniel@yesql.se>
2025-10-27 21:21 ` Nathan Bossart <nathandbossart@gmail.com>
2025-10-29 15:24 ` Peter Eisentraut <peter@eisentraut.org>
2025-10-29 15:48 ` Tom Lane <tgl@sss.pgh.pa.us>
2025-10-29 20:19 ` Daniel Gustafsson <daniel@yesql.se>
2025-11-03 20:57 ` Peter Eisentraut <peter@eisentraut.org>
2025-09-03 20:58 ` Greg Sabino Mullane <htamfids@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox