Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1aaf532

Browse files
committed
Rework option set of oid2name
oid2name has done little effort to keep an interface consistent withother binary utilities:- -H was used instead of -h/-host. This option is now marked asdeprecated, still its output is accepted to be backward-compatible.- -P has been removed from the code, and was still documented.- All options gain long aliases, making connection options more similarto other binaries.- Document environment variables which could be used: PGHOST, PGPORT andPGUSER.A basic set of TAP tests is added on the way, and documentation iscleaned up to be more consistent with other things.Author: Tatsuro YamadaReviewed-by: Michael PaquierDiscussion:https://postgr.es/m/c7e7f25c-1747-cd0f-9335-390bc97b2db5@lab.ntt.co.jp
1 parentc8ea87e commit1aaf532

File tree

5 files changed

+146
-69
lines changed

5 files changed

+146
-69
lines changed

‎contrib/oid2name/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
/oid2name
2+
3+
/tmp_check/

‎contrib/oid2name/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ top_builddir = ../..
1919
include$(top_builddir)/src/Makefile.global
2020
include$(top_srcdir)/contrib/contrib-global.mk
2121
endif
22+
23+
check:
24+
$(prove_check)
25+
26+
installcheck:
27+
$(prove_installcheck)

‎contrib/oid2name/oid2name.c

Lines changed: 67 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include"fe_utils/connect.h"
1515
#include"libpq-fe.h"
1616
#include"pg_getopt.h"
17+
#include"getopt_long.h"
18+
1719

1820
/* an extensible array to keep track of elements to show */
1921
typedefstruct
@@ -60,8 +62,28 @@ voidsql_exec_dumpalltbspc(PGconn *, struct options *);
6062
void
6163
get_opts(intargc,char**argv,structoptions*my_opts)
6264
{
65+
staticstructoptionlong_options[]= {
66+
{"dbname",required_argument,NULL,'d'},
67+
{"host",required_argument,NULL,'h'},
68+
{"host",required_argument,NULL,'H'},/* deprecated */
69+
{"filenode",required_argument,NULL,'f'},
70+
{"indexes",no_argument,NULL,'i'},
71+
{"oid",required_argument,NULL,'o'},
72+
{"port",required_argument,NULL,'p'},
73+
{"quiet",no_argument,NULL,'q'},
74+
{"tablespaces",no_argument,NULL,'s'},
75+
{"system-objects",no_argument,NULL,'S'},
76+
{"table",required_argument,NULL,'t'},
77+
{"username",required_argument,NULL,'U'},
78+
{"version",no_argument,NULL,'V'},
79+
{"extended",no_argument,NULL,'x'},
80+
{"help",no_argument,NULL,'?'},
81+
{NULL,0,NULL,0}
82+
};
83+
6384
intc;
6485
constchar*progname;
86+
intoptindex;
6587

6688
progname=get_progname(argv[0]);
6789

@@ -93,7 +115,7 @@ get_opts(int argc, char **argv, struct options *my_opts)
93115
}
94116

95117
/* get opts */
96-
while ((c=getopt(argc,argv,"H:p:U:d:t:o:f:qSxish"))!=-1)
118+
while ((c=getopt_long(argc,argv,"d:f:h:H:io:p:qsSt:U:x",long_options,&optindex))!=-1)
97119
{
98120
switch (c)
99121
{
@@ -102,66 +124,62 @@ get_opts(int argc, char **argv, struct options *my_opts)
102124
my_opts->dbname=pg_strdup(optarg);
103125
break;
104126

105-
/* specify one tablename to show */
106-
case't':
107-
add_one_elt(optarg,my_opts->tables);
108-
break;
109-
110-
/* specify one Oid to show */
111-
case'o':
112-
add_one_elt(optarg,my_opts->oids);
113-
break;
114-
115127
/* specify one filenode to show */
116128
case'f':
117129
add_one_elt(optarg,my_opts->filenodes);
118130
break;
119131

120-
/* don't show headers */
121-
case'q':
122-
my_opts->quiet= true;
123-
break;
124-
125132
/* host to connect to */
126-
case'H':
133+
case'H':/* deprecated */
134+
case'h':
127135
my_opts->hostname=pg_strdup(optarg);
128136
break;
129137

138+
/* also display indexes */
139+
case'i':
140+
my_opts->indexes= true;
141+
break;
142+
143+
/* specify one Oid to show */
144+
case'o':
145+
add_one_elt(optarg,my_opts->oids);
146+
break;
147+
130148
/* port to connect to on remote host */
131149
case'p':
132150
my_opts->port=pg_strdup(optarg);
133151
break;
134152

135-
/* username */
136-
case'U':
137-
my_opts->username=pg_strdup(optarg);
153+
/* don't show headers */
154+
case'q':
155+
my_opts->quiet= true;
156+
break;
157+
158+
/* dump tablespaces only */
159+
case's':
160+
my_opts->tablespaces= true;
138161
break;
139162

140163
/* display system tables */
141164
case'S':
142165
my_opts->systables= true;
143166
break;
144167

145-
/* also display indexes */
146-
case'i':
147-
my_opts->indexes= true;
168+
/* specify one tablename to show */
169+
case't':
170+
add_one_elt(optarg,my_opts->tables);
171+
break;
172+
173+
/* username */
174+
case'U':
175+
my_opts->username=pg_strdup(optarg);
148176
break;
149177

150178
/* display extra columns */
151179
case'x':
152180
my_opts->extended= true;
153181
break;
154182

155-
/* dump tablespaces only */
156-
case's':
157-
my_opts->tablespaces= true;
158-
break;
159-
160-
case'h':
161-
help(progname);
162-
exit(0);
163-
break;
164-
165183
default:
166184
fprintf(stderr,_("Try \"%s --help\" for more information.\n"),progname);
167185
exit(1);
@@ -176,20 +194,22 @@ help(const char *progname)
176194
"Usage:\n"
177195
" %s [OPTION]...\n"
178196
"\nOptions:\n"
179-
" -d DBNAME database to connect to\n"
180-
" -f FILENODE show info for table with given file node\n"
181-
" -H HOSTNAME database server host or socket directory\n"
182-
" -i show indexes and sequences too\n"
183-
" -o OID show info for table with given OID\n"
184-
" -p PORT database server port number\n"
185-
" -q quiet (don't show headers)\n"
186-
" -s show all tablespaces\n"
187-
" -S show system objects too\n"
188-
" -t TABLE show info for named table\n"
189-
" -U NAME connect as specified database user\n"
190-
" -V, --version output version information, then exit\n"
191-
" -x extended (show additional columns)\n"
192-
" -?, --help show this help, then exit\n"
197+
" -f, --filenode=FILENODE show info for table with given file node\n"
198+
" -i, --indexes show indexes and sequences too\n"
199+
" -o, --oid=OID show info for table with given OID\n"
200+
" -q, --quiet quiet (don't show headers)\n"
201+
" -s, --tablespaces show all tablespaces\n"
202+
" -S, --system-objects show system objects too\n"
203+
" -t, --table=TABLE show info for named table\n"
204+
" -V, --version output version information, then exit\n"
205+
" -x, --extended extended (show additional columns)\n"
206+
" -?, --help show this help, then exit\n"
207+
"\nConnection options:\n"
208+
" -d, --dbname=DBNAME database to connect to\n"
209+
" -h, --host=HOSTNAME database server host or socket directory\n"
210+
" -H same as -h, deprecated option\n"
211+
" -p, --port=PORT database server port number\n"
212+
" -U, --username=USERNAME connect as specified database user\n"
193213
"\nThe default action is to show all database OIDs.\n\n"
194214
"Report bugs to <pgsql-bugs@postgresql.org>.\n",
195215
progname,progname);

‎contrib/oid2name/t/001_basic.pl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use strict;
2+
use warnings;
3+
4+
use TestLib;
5+
use Test::Moretests=> 8;
6+
7+
#########################################
8+
# Basic checks
9+
10+
program_help_ok('oid2name');
11+
program_version_ok('oid2name');
12+
program_options_handling_ok('oid2name');

‎doc/src/sgml/oid2name.sgml

Lines changed: 59 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,41 +60,48 @@
6060
<variablelist>
6161

6262
<varlistentry>
63-
<term><option>-f</option> <replaceable>filenode</replaceable></term>
64-
<listitem><para>show info for table with filenode <replaceable>filenode</replaceable></para></listitem>
63+
<term><option>-f <replaceable class="parameter">filenode</replaceable></option></term>
64+
<term><option>--filenode=<replaceable class="parameter">filenode</replaceable></option></term>
65+
<listitem><para>show info for table with filenode <replaceable>filenode</replaceable>.</para></listitem>
6566
</varlistentry>
6667

6768
<varlistentry>
6869
<term><option>-i</option></term>
69-
<listitem><para>include indexes and sequences in the listing</para></listitem>
70+
<term><option>--indexes</option></term>
71+
<listitem><para>include indexes and sequences in the listing.</para></listitem>
7072
</varlistentry>
7173

7274
<varlistentry>
73-
<term><option>-o</option> <replaceable>oid</replaceable></term>
74-
<listitem><para>show info for table with OID <replaceable>oid</replaceable></para></listitem>
75+
<term><option>-o <replaceable class="parameter">oid</replaceable></option></term>
76+
<term><option>--oid=<replaceable class="parameter">oid</replaceable></option></term>
77+
<listitem><para>show info for table with OID <replaceable>oid</replaceable>.</para></listitem>
7578
</varlistentry>
7679

7780
<varlistentry>
7881
<term><option>-q</option></term>
79-
<listitem><para>omit headers (useful for scripting)</para></listitem>
82+
<term><option>--quiet</option></term>
83+
<listitem><para>omit headers (useful for scripting).</para></listitem>
8084
</varlistentry>
8185

8286
<varlistentry>
8387
<term><option>-s</option></term>
84-
<listitem><para>show tablespace OIDs</para></listitem>
88+
<term><option>--tablespaces</option></term>
89+
<listitem><para>show tablespace OIDs.</para></listitem>
8590
</varlistentry>
8691

8792
<varlistentry>
8893
<term><option>-S</option></term>
94+
<term><option>--system-objects</option></term>
8995
<listitem><para>include system objects (those in
9096
<option>information_schema</option>, <option>pg_toast</option>
91-
and <option>pg_catalog</option> schemas)
97+
and <option>pg_catalog</option> schemas).
9298
</para></listitem>
9399
</varlistentry>
94100

95101
<varlistentry>
96-
<term><option>-t</option> <replaceable>tablename_pattern</replaceable></term>
97-
<listitem><para>show info for table(s) matching <replaceable>tablename_pattern</replaceable></para></listitem>
102+
<term><option>-t <replaceable class="parameter">tablename_pattern</replaceable></option></term>
103+
<term><option>--table=<replaceable class="parameter">tablename_pattern</replaceable></option></term>
104+
<listitem><para>show info for table(s) matching <replaceable class="parameter">tablename_pattern</replaceable>.</para></listitem>
98105
</varlistentry>
99106

100107
<varlistentry>
@@ -109,8 +116,9 @@
109116

110117
<varlistentry>
111118
<term><option>-x</option></term>
119+
<term><option>--extended</option></term>
112120
<listitem><para>display more information about each object shown: tablespace name,
113-
schema name, and OID
121+
schema name, and OID.
114122
</para></listitem>
115123
</varlistentry>
116124

@@ -133,29 +141,34 @@
133141

134142
<variablelist>
135143
<varlistentry>
136-
<term><option>-d</option> <replaceable>database</replaceable></term>
137-
<listitem><para>database to connect to</para></listitem>
144+
<term><option>-d <replaceable class="parameter">database</replaceable></option></term>
145+
<term><option>--dbname=<replaceable class="parameter">database</replaceable></option></term>
146+
<listitem><para>database to connect to.</para></listitem>
138147
</varlistentry>
139148

140149
<varlistentry>
141-
<term><option>-H</option> <replaceable>host</replaceable></term>
142-
<listitem><para>database server's host</para></listitem>
150+
<term><option>-h <replaceable class="parameter">host</replaceable></option></term>
151+
<term><option>--host=<replaceable class="parameter">host</replaceable></option></term>
152+
<listitem><para>database server's host.</para></listitem>
143153
</varlistentry>
144154

145155
<varlistentry>
146-
<term><option>-p</option> <replaceable>port</replaceable></term>
147-
<listitem><para>database server's port</para></listitem>
156+
<term><option>-H <replaceable class="parameter">host</replaceable></option></term>
157+
<listitem><para>database server's host. Use of this parameter is
158+
<emphasis>deprecated</emphasis> as of
159+
<productname>PostgreSQL</productname> 12.</para></listitem>
148160
</varlistentry>
149161

150162
<varlistentry>
151-
<term><option>-U</option> <replaceable>username</replaceable></term>
152-
<listitem><para>user name to connect as</para></listitem>
163+
<term><option>-p <replaceable class="parameter">port</replaceable></option></term>
164+
<term><option>--port=<replaceable class="parameter">port</replaceable></option></term>
165+
<listitem><para>database server's port.</para></listitem>
153166
</varlistentry>
154167

155168
<varlistentry>
156-
<term><option>-P</option> <replaceable>password</replaceable></term>
157-
<listitem><para>password (deprecated &mdash; putting this on the command line
158-
is a security hazard)</para></listitem>
169+
<term><option>-U <replaceable class="parameter">username</replaceable></option></term>
170+
<term><option>--username=<replaceable class="parameter">username</replaceable></option></term>
171+
<listitem><para>user name to connect as.</para></listitem>
159172
</varlistentry>
160173

161174
</variablelist>
@@ -188,6 +201,30 @@
188201
</para>
189202
</refsect1>
190203

204+
<refsect1>
205+
<title>Environment</title>
206+
207+
<variablelist>
208+
<varlistentry>
209+
<term><envar>PGHOST</envar></term>
210+
<term><envar>PGPORT</envar></term>
211+
<term><envar>PGUSER</envar></term>
212+
213+
<listitem>
214+
<para>
215+
Default connection parameters.
216+
</para>
217+
</listitem>
218+
</varlistentry>
219+
</variablelist>
220+
221+
<para>
222+
This utility, like most other <productname>PostgreSQL</productname>
223+
utilities, also uses the environment variables supported by
224+
<application>libpq</application> (see <xref linkend="libpq-envars"/>).
225+
</para>
226+
</refsect1>
227+
191228
<refsect1>
192229
<title>Notes</title>
193230

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp