pgbench: improve --help and --version parsing - Mailing list pgsql-hackers

From Andrei Korigodski
Subject pgbench: improve --help and --version parsing
Date
Msg-id c50e18df-8f53-0b3e-8bb4-27be8598c954@gmail.com
Whole thread Raw
Responses Re: pgbench: improve --help and --version parsing  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hi,

There is a small catch in the parsing of --help and --version args by pgbench:
they are processed correctly only as the first argument. If it's not the case,
strange error message occurs:

$ pgbench -q --help
pgbench: unrecognized option '--help'
Try "pgbench --help" for more information.

The reason for this behavior is how these two arguments are handled in
src/bin/pgbench/pgbench.c:

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);
    }
}

All other arguments are processed with getopt_long. The proposed patch replaces
the existing way of parsing the --help and --version arguments with getopt_long,
expanding the existing switch statement.

--
Andrei Korigodski


Attachment

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Remove psql's -W option
Next
From: Davy Machado
Date:
Subject: Re: pg_ugprade test failure on data set with column with default valuewith type bit/varbit