diff --git a/contrib/oid2name/.gitignore b/contrib/oid2name/.gitignore index fdefde108d..0410fb7afa 100644 --- a/contrib/oid2name/.gitignore +++ b/contrib/oid2name/.gitignore @@ -1 +1,3 @@ /oid2name + +/tmp_check/ diff --git a/contrib/oid2name/Makefile b/contrib/oid2name/Makefile index 3eef8f60be..77b72880f5 100644 --- a/contrib/oid2name/Makefile +++ b/contrib/oid2name/Makefile @@ -19,3 +19,9 @@ top_builddir = ../.. include $(top_builddir)/src/Makefile.global include $(top_srcdir)/contrib/contrib-global.mk endif + +check: + $(prove_check) + +installcheck: + $(prove_installcheck) diff --git a/contrib/oid2name/oid2name.c b/contrib/oid2name/oid2name.c index 63e360c4c5..aa122ca0e9 100644 --- a/contrib/oid2name/oid2name.c +++ b/contrib/oid2name/oid2name.c @@ -14,6 +14,8 @@ #include "fe_utils/connect.h" #include "libpq-fe.h" #include "pg_getopt.h" +#include "getopt_long.h" + /* an extensible array to keep track of elements to show */ typedef struct @@ -60,8 +62,28 @@ void sql_exec_dumpalltbspc(PGconn *, struct options *); void get_opts(int argc, char **argv, struct options *my_opts) { + static struct option long_options[] = { + {"dbname", required_argument, NULL, 'd'}, + {"host", required_argument, NULL, 'h'}, + {"host", required_argument, NULL, 'H'}, /* deprecated */ + {"filenode", required_argument, NULL, 'f'}, + {"indexes", no_argument, NULL, 'i'}, + {"oid", required_argument, NULL, 'o'}, + {"port", required_argument, NULL, 'p'}, + {"quiet", no_argument, NULL, 'q'}, + {"tablespaces", no_argument, NULL, 's'}, + {"system-objects", no_argument, NULL, 'S'}, + {"table", required_argument, NULL, 't'}, + {"username", required_argument, NULL, 'U'}, + {"version", no_argument, NULL, 'V'}, + {"extended", no_argument, NULL, 'x'}, + {"help", no_argument, NULL, '?'}, + {NULL, 0, NULL, 0} + }; + int c; const char *progname; + int optindex; progname = get_progname(argv[0]); @@ -93,7 +115,7 @@ get_opts(int argc, char **argv, struct options *my_opts) } /* get opts */ - while ((c = getopt(argc, argv, "H:p:U:d:t:o:f:qSxish")) != -1) + while ((c = getopt_long(argc, argv, "d:f:h:H:io:p:qsSt:U:x", long_options, &optindex)) != -1) { switch (c) { @@ -102,54 +124,35 @@ get_opts(int argc, char **argv, struct options *my_opts) my_opts->dbname = pg_strdup(optarg); break; - /* specify one tablename to show */ - case 't': - add_one_elt(optarg, my_opts->tables); - break; - - /* specify one Oid to show */ - case 'o': - add_one_elt(optarg, my_opts->oids); - break; - /* specify one filenode to show */ case 'f': add_one_elt(optarg, my_opts->filenodes); break; - /* don't show headers */ - case 'q': - my_opts->quiet = true; - break; - /* host to connect to */ - case 'H': + case 'H': /* deprecated */ + case 'h': my_opts->hostname = pg_strdup(optarg); break; - /* port to connect to on remote host */ - case 'p': - my_opts->port = pg_strdup(optarg); - break; - - /* username */ - case 'U': - my_opts->username = pg_strdup(optarg); - break; - - /* display system tables */ - case 'S': - my_opts->systables = true; - break; - /* also display indexes */ case 'i': my_opts->indexes = true; break; - /* display extra columns */ - case 'x': - my_opts->extended = true; + /* specify one Oid to show */ + case 'o': + add_one_elt(optarg, my_opts->oids); + break; + + /* port to connect to on remote host */ + case 'p': + my_opts->port = pg_strdup(optarg); + break; + + /* don't show headers */ + case 'q': + my_opts->quiet = true; break; /* dump tablespaces only */ @@ -157,9 +160,24 @@ get_opts(int argc, char **argv, struct options *my_opts) my_opts->tablespaces = true; break; - case 'h': - help(progname); - exit(0); + /* display system tables */ + case 'S': + my_opts->systables = true; + break; + + /* specify one tablename to show */ + case 't': + add_one_elt(optarg, my_opts->tables); + break; + + /* username */ + case 'U': + my_opts->username = pg_strdup(optarg); + break; + + /* display extra columns */ + case 'x': + my_opts->extended = true; break; default: @@ -176,20 +194,22 @@ help(const char *progname) "Usage:\n" " %s [OPTION]...\n" "\nOptions:\n" - " -d DBNAME database to connect to\n" - " -f FILENODE show info for table with given file node\n" - " -H HOSTNAME database server host or socket directory\n" - " -i show indexes and sequences too\n" - " -o OID show info for table with given OID\n" - " -p PORT database server port number\n" - " -q quiet (don't show headers)\n" - " -s show all tablespaces\n" - " -S show system objects too\n" - " -t TABLE show info for named table\n" - " -U NAME connect as specified database user\n" - " -V, --version output version information, then exit\n" - " -x extended (show additional columns)\n" - " -?, --help show this help, then exit\n" + " -f, --filenode=FILENODE show info for table with given file node\n" + " -i, --indexes show indexes and sequences too\n" + " -o, --oid=OID show info for table with given OID\n" + " -q, --quiet quiet (don't show headers)\n" + " -s, --tablespaces show all tablespaces\n" + " -S, --system-objects show system objects too\n" + " -t, --table=TABLE show info for named table\n" + " -V, --version output version information, then exit\n" + " -x, --extended extended (show additional columns)\n" + " -?, --help show this help, then exit\n" + "\nConnection options:\n" + " -d, --dbname=DBNAME database to connect to\n" + " -h, --host=HOSTNAME database server host or socket directory\n" + " -H same as -h, deprecated option\n" + " -p, --port=PORT database server port number\n" + " -U, --username=USERNAME connect as specified database user\n" "\nThe default action is to show all database OIDs.\n\n" "Report bugs to .\n", progname, progname); diff --git a/contrib/oid2name/t/001_basic.pl b/contrib/oid2name/t/001_basic.pl new file mode 100644 index 0000000000..fa2c5743f6 --- /dev/null +++ b/contrib/oid2name/t/001_basic.pl @@ -0,0 +1,12 @@ +use strict; +use warnings; + +use TestLib; +use Test::More tests => 8; + +######################################### +# Basic checks + +program_help_ok('oid2name'); +program_version_ok('oid2name'); +program_options_handling_ok('oid2name'); diff --git a/doc/src/sgml/oid2name.sgml b/doc/src/sgml/oid2name.sgml index dd875281c8..c7ebd61c6b 100644 --- a/doc/src/sgml/oid2name.sgml +++ b/doc/src/sgml/oid2name.sgml @@ -60,41 +60,48 @@ - filenode - show info for table with filenode filenode + + + show info for table with filenode filenode. - include indexes and sequences in the listing + + include indexes and sequences in the listing. - oid - show info for table with OID oid + + + show info for table with OID oid. - omit headers (useful for scripting) + + omit headers (useful for scripting). - show tablespace OIDs + + show tablespace OIDs. + include system objects (those in , - and schemas) + and schemas). - tablename_pattern - show info for table(s) matching tablename_pattern + + + show info for table(s) matching tablename_pattern. @@ -109,8 +116,9 @@ + display more information about each object shown: tablespace name, - schema name, and OID + schema name, and OID. @@ -133,29 +141,34 @@ - database - database to connect to + + + database to connect to. - host - database server's host + + + database server's host. - port - database server's port + + database server's host. Use of this parameter is + deprecated as of + PostgreSQL 12. - username - user name to connect as + + + database server's port. - password - password (deprecated — putting this on the command line - is a security hazard) + + + user name to connect as. @@ -188,6 +201,30 @@ + + Environment + + + + PGHOST + PGPORT + PGUSER + + + + Default connection parameters. + + + + + + + This utility, like most other PostgreSQL + utilities, also uses the environment variables supported by + libpq (see ). + + + Notes