Skip to content

Commit 8df6b2b

Browse files
committed
Add --version and --help options to "postgres".
1 parent 6707ede commit 8df6b2b

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

src/backend/tcop/postgres.c

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.182 2000/10/26 17:31:35 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.183 2000/10/28 01:07:00 petere Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -1111,7 +1111,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
11111111

11121112
optind = 1; /* reset after postmaster's usage */
11131113

1114-
while ((flag = getopt(argc, argv, "A:B:CD:d:Eef:FiLNOPo:p:S:st:v:W:x:-:")) != EOF)
1114+
while ((flag = getopt(argc, argv, "A:B:CD:d:Eef:FiLNOPo:p:S:st:v:W:x:-:?")) != EOF)
11151115
switch (flag)
11161116
{
11171117
case 'A':
@@ -1385,6 +1385,16 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
13851385
char *name, *value;
13861386

13871387
ParseLongOption(optarg, &name, &value);
1388+
if (strcmp(name, "help")==0)
1389+
{
1390+
usage(argv[0]);
1391+
exit(0);
1392+
}
1393+
else if (strcmp(name, "version")==0)
1394+
{
1395+
puts("postgres (PostgreSQL) " PG_VERSION);
1396+
exit(0);
1397+
}
13881398
if (!value)
13891399
elog(ERROR, "--%s requires argument", optarg);
13901400

@@ -1395,15 +1405,23 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
13951405
break;
13961406
}
13971407

1408+
case '?':
1409+
if (strcmp(argv[optind - 1], "-?") == 0)
1410+
{
1411+
usage(argv[0]);
1412+
exit(0);
1413+
}
1414+
else
1415+
errs++;
1416+
break;
1417+
13981418
default:
1399-
/* ----------------
1400-
* default: bad command line option
1401-
* ----------------
1402-
*/
1419+
/* shouldn't get here */
14031420
errs++;
14041421
break;
14051422
}
14061423

1424+
14071425
if (Show_query_stats &&
14081426
(Show_parser_stats || Show_planner_stats || Show_executor_stats))
14091427
{
@@ -1470,8 +1488,8 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
14701488
/* noninteractive case: nothing should be left after switches */
14711489
if (errs || argc != optind || DBName == NULL)
14721490
{
1473-
usage(argv[0]);
1474-
proc_exit(0);
1491+
fprintf(stderr, "%s: invalid command line arguments\nTry -? for help.\n", argv[0]);
1492+
proc_exit(1);
14751493
}
14761494
pq_init(); /* initialize libpq at backend startup */
14771495
whereToSendOutput = Remote;
@@ -1483,16 +1501,16 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
14831501
whereToSendOutput = Debug;
14841502
if (errs || argc - optind > 1)
14851503
{
1486-
usage(argv[0]);
1487-
proc_exit(0);
1504+
fprintf(stderr, "%s: invalid command line arguments\nTry -? for help.\n", argv[0]);
1505+
proc_exit(1);
14881506
}
14891507
else if (argc - optind == 1)
14901508
DBName = argv[optind];
14911509
else if ((DBName = username) == NULL)
14921510
{
14931511
fprintf(stderr, "%s: user name undefined and no database specified\n",
14941512
argv[0]);
1495-
proc_exit(0);
1513+
proc_exit(1);
14961514
}
14971515

14981516
/*
@@ -1618,7 +1636,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
16181636
if (!IsUnderPostmaster)
16191637
{
16201638
puts("\nPOSTGRES backend interactive interface ");
1621-
puts("$Revision: 1.182 $ $Date: 2000/10/26 17:31:35 $\n");
1639+
puts("$Revision: 1.183 $ $Date: 2000/10/28 01:07:00 $\n");
16221640
}
16231641

16241642
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy