8000 Revert recent commit re positional arguments. · jcsston/postgres@5969ee4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5969ee4

Browse files
committed
Revert recent commit re positional arguments.
1 parent 4fd49c7 commit 5969ee4

File tree

6 files changed

+38
-75
lines changed

6 files changed

+38
-75
lines changed

src/bin/initdb/initdb.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2563,11 +2563,8 @@ main(int argc, char *argv[])
25632563
}
25642564

25652565

2566-
/*
2567-
* Non-option argument specifies data directory
2568-
* as long as it wasn't already specified with -D / --pgdata
2569-
*/
2570-
if (optind < argc && strlen(pg_data) == 0)
2566+
/* Non-option argument specifies data directory */
2567+
if (optind < argc)
25712568
{
25722569
pg_data = xstrdup(argv[optind]);
25732570
optind++;

src/bin/scripts/clusterdb.c

Lines changed: 11 additions & 15 deletions
< 10000 td data-grid-cell-id="diff-1408dc5b297c15a487d8644f2ecdd841a5ab3b6f8915dde78fe0bce79f617230-114-110-0" data-selected="false" role="gridcell" style="background-color:var(--bgColor-default);text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative diff-line-number-neutral left-side">114
Original file line numberDiff line numberDiff line change
@@ -106,22 +106,18 @@ main(int argc, char *argv[])
106106
}
107107
}
108108

109-
/*
110-
* Non-option argument specifies database name
111-
* as long as it wasn't already specified with -d / --dbname
112-
*/
113-
if (optind < argc && dbname == NULL)
109+
switch (argc - optind)
110
{
115-
dbname = argv[optind];
116-
optind++;
117-
}
118-
119-
if (optind < argc)
120-
{
121-
fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"),
122-
progname, argv[optind + 1]);
123-
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
124-
exit(1);
111+
case 0:
112+
break;
113+
case 1:
114+
dbname = argv[optind];
115+
break;
116+
default:
117+
fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"),
118+
progname, argv[optind + 1]);
119+
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
120+
exit(1);
125121
}
126122

127123
setup_cancel_handler();

src/bin/scripts/createlang.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,24 +91,14 @@ main(int argc, char *argv[])
9191
}
9292
}
9393

94-
/*
95-
* We set dbname from positional arguments if it is not
96-
* already set by option arguments -d. If not doing
97-
* listlangs, positional dbname must follow positional
98-
* langname.
99-
*/
100-
10194
if (argc - optind > 0)
10295
{
10396
if (listlangs)
104-
{
105-
if (dbname == NULL)
106-
dbname = argv[optind++];
107-
}
97+
dbname = argv[optind++];
10898
else
10999
{
110100
langname = argv[optind++];
111-
if (argc - optind > 0 && dbname == NULL)
101+
if (argc - optind > 0)
112102
dbname = argv[optind++];
113103
}
114104
}

src/bin/scripts/droplang.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,24 +102,14 @@ main(int argc, char *argv[])
102102
}
103103
}
104104

105-
/*
106-
* We set dbname from positional arguments if it is not
107-
* already set by option arguments -d. If not doing
108-
* listlangs, positional dbname must follow positional
109-
* langname.
110-
*/
111-
112105
if (argc - optind > 0)
113106
{
114107
if (listlangs)
115-
{
116-
if (dbname == NULL)
117-
dbname = argv[optind++];
118-
}
108+
dbname = argv[optind++];
119109
else
120110
{
121111
langname = argv[optind++];
122-
if (argc - optind > 0 && dbname == NULL)
112+
if (argc - optind > 0)
123113
dbname = argv[optind++];
124114
}
125115
}

src/bin/scripts/reindexdb.c

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -116,22 +116,17 @@ main(int argc, char *argv[])
116116
}
117117
}
118118

119-
/*
120-
* Non-option argument specifies database name
121-
* as long as it wasn't already specified with -d / --dbname
122-
*/
123-
if (optind < argc && dbname == NULL)
119+
switch (argc - optind)
124120
{
125-
dbname = argv[optind];
126-
optind++;
127-
}
128-
129-
if (optind < argc)
130-
{
131-
fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"),
132-
progname, argv[optind + 1]);
133-
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
134-
exit(1);
121+
case 0:
122+
break;
123+
case 1:
124+
dbname = argv[optind];
125+
break;
126+
default:
127+
fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"), progname, argv[optind + 1]);
128+
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
129+
exit(1);
135130
}
136131

137132
setup_cancel_handler();

src/bin/scripts/vacuumdb.c

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -129,23 +129,18 @@ main(int argc, char *argv[])
129129
}
130130
}
131131

132-
133-
/*
134-
* Non-option argument specifies database name
135-
* as long as it wasn't already specified with -d / --dbname
136-
*/
137-
if (optind < argc && dbname == NULL)
132+
switch (argc - optind)
138133
{
139-
dbname = argv[optind];
140-
optind++;
141-
}
142-
143-
if (optind < argc)
144-
{
145-
fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"),
146-
progname, argv[optind + 1]);
147-
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
148-
exit(1);
134+
case 0:
135+
break;
136+
case 1:
137+
dbname = argv[optind];
138+
break;
139+
default:
140+
fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"),
141+
progname, argv[optind + 1]);
142+
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
143+
exit(1);
149144
}
150145

151146
if (analyze_only)

0 commit comments

Comments
 (0)
0