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

Commit41fde54

Browse files
committed
Polish help output. Allow --help to work with BSD getopts.
1 parent24a4aff commit41fde54

File tree

2 files changed

+125
-104
lines changed

2 files changed

+125
-104
lines changed

‎src/bin/pg_dump/pg_dump.c

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
*
2424
* IDENTIFICATION
25-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.184 2001/01/04 01:23:47 tgl Exp $
25+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.185 2001/01/06 20:57:26 petere Exp $
2626
*
2727
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2828
*
@@ -193,24 +193,27 @@ help(const char *progname)
193193
#ifdefHAVE_GETOPT_LONG
194194
puts(
195195
" -a, --data-only dump out only the data, not the schema\n"
196-
" -b, --blobsdump out blob data\n"
196+
" -b, --blobsdump out blob data\n"
197197
" -c, --clean clean (drop) schema prior to create\n"
198198
" -C, --create output commands to create database\n"
199199
" -d, --inserts dump data as INSERT, rather than COPY, commands\n"
200200
" -D, --attribute-inserts dump data as INSERT commands with attribute names\n"
201-
" -f, --file specify output file name\n"
201+
" -f, --file=FILENAME specify output file name\n"
202202
" -F, --format {c|f|p} output file format (custom, files, plain text)\n"
203-
" -h, --host <hostname> server host name\n"
203+
" -h, --host=HOSTNAME server host name\n"
204204
" -i, --ignore-version proceed when database version != pg_dump version\n"
205205
" -n, --no-quotes suppress most quotes around identifiers\n"
206206
" -N, --quotes enable most quotes around identifiers\n"
207207
" -o, --oids dump object ids (oids)\n"
208-
" -O, --no-owner don't output \\connect commands in plain text format\n"
209-
" -p, --port <port> server port number\n"
210-
" -R, --no-reconnect disable ALL reconnections to the database in plain text format\n"
208+
" -O, --no-owner do not output \\connect commands in plain text\n"
209+
" format\n"
210+
" -p, --port=PORT server port number\n"
211+
" -R, --no-reconnect disable ALL reconnections to the database in\n"
212+
" plain text format\n"
211213
" -s, --schema-only dump out only the schema, no data\n"
212-
" -S, --superuser <name> specify the superuser username to use in plain text format\n"
213-
" -t, --table <table> dump for this table only\n"
214+
" -S, --superuser=NAME specify the superuser user name to use in plain\n"
215+
" text format\n"
216+
" -t, --table=TABLE dump for this table only\n"
214217
" -u, --password use password authentication\n"
215218
" -v, --verbose verbose\n"
216219
" -x, --no-acl do not dump ACL's (grant/revoke)\n"
@@ -224,19 +227,22 @@ help(const char *progname)
224227
" -C output commands to create database\n"
225228
" -d dump data as INSERT, rather than COPY, commands\n"
226229
" -D dump data as INSERT commands with attribute names\n"
227-
" -f specify output file name\n"
230+
" -fFILENAME specify output file name\n"
228231
" -F {c|f|p} output file format (custom, files, plain text)\n"
229-
" -h<hostname> server host name\n"
232+
" -hHOSTNAME server host name\n"
230233
" -i proceed when database version != pg_dump version\n"
231234
" -n suppress most quotes around identifiers\n"
232235
" -N enable most quotes around identifiers\n"
233236
" -o dump object ids (oids)\n"
234-
" -O don't output \\connect commands in plain text format\n"
235-
" -p <port> server port number\n"
236-
" -R disable ALL reconnections to the database in plain text format\n"
237+
" -O do not output \\connect commands in plain text\n"
238+
" format\n"
239+
" -p PORT server port number\n"
240+
" -R disable ALL reconnections to the database in\n"
241+
" plain text format\n"
237242
" -s dump out only the schema, no data\n"
238-
" -S <name> specify the superuser username to use in plain text format\n"
239-
" -t <table> dump for this table only\n"
243+
" -S NAME specify the superuser user name to use in plain\n"
244+
" text format\n"
245+
" -t TABLE dump for this table only\n"
240246
" -u use password authentication\n"
241247
" -v verbose\n"
242248
" -x do not dump ACL's (grant/revoke)\n"
@@ -253,7 +259,7 @@ version(void)
253259
{
254260
puts("pg_dump (PostgreSQL) "PG_VERSION);
255261
puts("Portions Copyright (c) 1996-2000, PostgreSQL, Inc");
256-
puts("Portions Copyright (C) 1996 Regents of the University of California");
262+
puts("Portions Copyright (c) 1996 Regents of the University of California");
257263
puts("Read the file COPYRIGHT to see the usage and distribution terms.");
258264
}
259265

@@ -718,10 +724,24 @@ main(int argc, char **argv)
718724
outputBlobs= true;
719725
}
720726

727+
if (argc>1)
728+
{
729+
if (strcmp(argv[1],"--help")==0||strcmp(argv[1],"-?")==0)
730+
{
731+
help(progname);
732+
exit(0);
733+
}
734+
if (strcmp(argv[1],"--version")==0||strcmp(argv[1],"-V")==0)
735+
{
736+
version();
737+
exit(0);
738+
}
739+
}
740+
721741
#ifdefHAVE_GETOPT_LONG
722-
while ((c=getopt_long(argc,argv,"abcCdDf:F:h:inNoOp:sS:t:uvxzZ:V?",long_options,&optindex))!=-1)
742+
while ((c=getopt_long(argc,argv,"abcCdDf:F:h:inNoOp:RsS:t:uvxzZ:V?",long_options,&optindex))!=-1)
723743
#else
724-
while ((c=getopt(argc,argv,"abcCdDf:F:h:inNoOp:sS:t:uvxzZ:V?-"))!=-1)
744+
while ((c=getopt(argc,argv,"abcCdDf:F:h:inNoOp:RsS:t:uvxzZ:V?-"))!=-1)
725745
#endif
726746

727747
{
@@ -852,40 +872,23 @@ main(int argc, char **argv)
852872
exit(0);
853873
break;
854874

855-
case'?':
856-
857-
/*
858-
* getopt returns '?' on unknown argument. That's not
859-
* quite what we want
860-
*/
861-
if (strcmp(argv[optind-1],"-?")==0||strcmp(argv[optind-1],"--help")==0)
862-
{
863-
help(progname);
864-
exit(1);
865-
}
866-
else
867-
{
868-
fputs("Try -? for help.\n",stderr);
869-
exit(1);
870-
}
871-
break;
872875
#ifndefHAVE_GETOPT_LONG
873876
case'-':
874877
fprintf(stderr,"%s was compiled without support for long options.\n"
875-
"Use -? for help on invocation options.\n",progname);
878+
"Use --help for help on invocation options.\n",progname);
876879
exit(1);
877880
break;
878881
#endif
879882
default:
880-
fprintf(stderr,"%s: unknown option -%c\nTry -? forhelp.\n",progname,c);
883+
fprintf(stderr,"Try '%s --help' formore information.\n",progname);
881884
exit(1);
882885
}
883886
}
884887

885888
if (optind< (argc-1)) {
886889
fprintf(stderr,
887890
"%s: extra parameters found on command line after '%s' (first is '%s').\n"
888-
"Please respecify command.\nUse -? for help on invocation options.\n",
891+
"Please respecify command.\nUse --help for help on invocation options.\n",
889892
progname,argv[optind],argv[optind+1]);
890893
exit(1);
891894
}

‎src/bin/pg_dump/pg_restore.c

Lines changed: 83 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,21 @@ int main(int argc, char **argv)
129129

130130
opts=NewRestoreOptions();
131131

132-
progname=*argv;
132+
progname=argv[0];
133+
134+
if (argc>1)
135+
{
136+
if (strcmp(argv[1],"--help")==0||strcmp(argv[1],"-?")==0)
137+
{
138+
usage(progname);
139+
exit(0);
140+
}
141+
if (strcmp(argv[1],"--version")==0||strcmp(argv[1],"-V")==0)
142+
{
143+
puts("pg_restore (PostgreSQL) "PG_VERSION);
144+
exit(0);
145+
}
146+
}
133147

134148
#ifdefHAVE_GETOPT_LONG
135149
while ((c=getopt_long(argc,argv,"acCd:f:F:h:i:lNoOp:P:rRsS:t:T:uU:vx",cmdopts,NULL))!=EOF)
@@ -235,8 +249,8 @@ int main(int argc, char **argv)
235249
opts->aclsSkip=1;
236250
break;
237251
default:
238-
usage(progname);
239-
break;
252+
fprintf(stderr,"Try '%s --help' for more information.\n",progname);
253+
exit(1);
240254
}
241255
}
242256

@@ -311,72 +325,76 @@ int main(int argc, char **argv)
311325

312326
staticvoidusage(constchar*progname)
313327
{
328+
printf("%s restores a PostgreSQL database from an archive created by pg_dump.\n\n"
329+
"Usage:\n %s [options] [backup file]\n\n"
330+
"Options:\n",
331+
progname,progname);
314332
#ifdefHAVE_GETOPT_LONG
315-
fprintf(stderr,
316-
"usage: %s [options] [backup file]\n"
317-
" -a, --data-only \t dump out only the data, no schema\n"
318-
" -d, --dbname <name> \t specify database name\n"
319-
" -c, --clean \t clean(drop) schema prior to create\n"
320-
" -C, --create \t output commands to create the database\n"
321-
" -f filename \t script output filename\n"
322-
" -F, --format {c|f} \t specify backup file format\n"
323-
" -h, --host <hostname> \t server host name\n"
324-
" -i, --index[=name] \t dump indexes or named index\n"
325-
" -l, --list \t dump summarized TOC for this file\n"
326-
" -N, --orig-order \t dump in original dump order\n"
327-
" -o, --oid-order \t dump in oid order\n"
328-
" -O, --no-owner \t don't output reconnect to database to match object owner\n"
329-
" -p, --port <port> \t server port number\n"
330-
" -P, --function[=name] \t dump functions or named function\n"
331-
" -r, --rearrange \t rearrange output to put indexes etc at end\n"
332-
" -R, --no-reconnect \t disallow ALL reconnections to the database\n"
333-
" -s, --schema-only \t dump out only the schema, no data\n"
334-
" -S, --superuser <name> \t specify the superuser username to use in disabling triggers\n"
335-
" -t [table], --table[=table] \t dump for this table only\n"
336-
" -T, --trigger[=name] \t dump triggers or named trigger\n"
337-
" -u, --password \t use password authentication\n"
338-
" -U, --use-list filename \t use specified TOC for ordering output from this file\n"
339-
" -v, --verbose \t verbose\n"
340-
" -x, --no-acl \t skip dumping of ACLs (grant/revoke)\n"
341-
,progname);
342-
343-
#else
344-
fprintf(stderr,
345-
"usage: %s [options] [backup file]\n"
346-
" -a \t dump out only the data, no schema\n"
347-
" -d <name> \t specify database name\n"
348-
" -c \t clean(drop) schema prior to create\n"
349-
" -C \t output commands to create the database\n"
350-
" -f filename \t script output filename\n"
351-
" -F {c|f} \t specify backup file format\n"
352-
" -h <hostname> \t server host name\n"
353-
" -i name \t dump indexes or named index\n"
354-
" -l \t dump summarized TOC for this file\n"
355-
" -N \t dump in original dump order\n"
356-
" -o \t dump in oid order\n"
357-
" -O \t don't output reconnect to database to match object owner\n"
358-
" -p <port> \t server port number\n"
359-
" -P name \t dump functions or named function\n"
360-
" -r \t rearrange output to put indexes etc at end\n"
361-
" -R \t disallow ALL reconnections to the database\n"
362-
" -s \t dump out only the schema, no data\n"
363-
" -S <name> \t specify the superuser username to use in disabling triggers\n"
364-
" -t name \t dump for this table only\n"
365-
" -T name \t dump triggers or named trigger\n"
366-
" -u \t use password authentication\n"
367-
" -U filename \t use specified TOC for ordering output from this file\n"
368-
" -v \t verbose\n"
369-
" -x \t skip dumping of ACLs (grant/revoke)\n"
370-
,progname);
333+
puts(
334+
" -a, --data-only dump out only the data, no schema\n"
335+
" -c, --clean clean (drop) schema prior to create\n"
336+
" -C, --create output commands to create the database\n"
337+
" -d, --dbname=NAME specify database name\n"
338+
" -f, --file=FILENAME script output file name\n"
339+
" -F, --format {c|f} specify backup file format\n"
340+
" -h, --host HOSTNAME server host name\n"
341+
" -i, --index[=NAME] dump indexes or named index\n"
342+
" -l, --list dump summarized TOC for this file\n"
343+
" -N, --orig-order dump in original dump order\n"
344+
" -o, --oid-order dump in oid order\n"
345+
" -O, --no-owner do not output reconnect to database to match\n"
346+
" object owner\n"
347+
" -p, --port PORT server port number\n"
348+
" -P, --function[=NAME] dump functions or named function\n"
349+
" -r, --rearrange rearrange output to put indexes etc. at end\n"
350+
" -R, --no-reconnect disallow ALL reconnections to the database\n"
351+
" -s, --schema-only dump out only the schema, no data\n"
352+
" -S, --superuser=NAME specify the superuser user name to use for\n"
353+
" disabling triggers\n"
354+
" -t [TABLE], --table[=TABLE] dump for this table only\n"
355+
" -T, --trigger[=NAME] dump triggers or named trigger\n"
356+
" -u, --password use password authentication\n"
357+
" -U, --use-list=FILENAME use specified table of contents for ordering\n"
358+
" output from this file\n"
359+
" -v, --verbose verbose\n"
360+
" -x, --no-acl skip dumping of ACLs (grant/revoke)\n");
361+
362+
#else/* not HAVE_GETOPT_LONG */
363+
364+
puts(
365+
" -a dump out only the data, no schema\n"
366+
" -c clean (drop) schema prior to create\n"
367+
" -C output commands to create the database\n"
368+
" -d NAME specify database name\n"
369+
" -f FILENAME script output file name\n"
370+
" -F {c|f} specify backup file format\n"
371+
" -h HOSTNAME server host name\n"
372+
" -i NAME dump indexes or named index\n"
373+
" -l dump summarized TOC for this file\n"
374+
" -N dump in original dump order\n"
375+
" -o dump in oid order\n"
376+
" -O do not output reconnect to database to match\n"
377+
" object owner\n"
378+
" -p PORT server port number\n"
379+
" -P NAME dump functions or named function\n"
380+
" -r rearrange output to put indexes etc at end\n"
381+
" -R disallow ALL reconnections to the database\n"
382+
" -s dump out only the schema, no data\n"
383+
" -S NAME specify the superuser user name to use for\n"
384+
" disabling triggers\n"
385+
" -t NAME dump for this table only\n"
386+
" -T NAME dump triggers or named trigger\n"
387+
" -u use password authentication\n"
388+
" -U FILENAME use specified table of contents for ordering\n"
389+
" output from this file\n"
390+
" -v verbose\n"
391+
" -x skip dumping of ACLs (grant/revoke)\n");
371392
#endif
372-
fprintf(stderr,
373-
"\nIf [backup file] is not supplied, then standard input "
374-
"is used.\n");
375-
fprintf(stderr,"\n");
376-
377-
exit(1);
393+
puts("If [backup file] is not supplied, then standard input is used.\n");
394+
puts("Report bugs to <pgsql-bugs@postgresql.org>.");
378395
}
379396

397+
380398
staticchar*_cleanupName(char*name)
381399
{
382400
inti;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp