Skip to content

Commit 50e4c28

Browse files
committed
createuser: Cleanup and fix internal option ordering
This utility supports 23 options that are not really ordered in the code, making the addition of new things more complicated than necessary. This cleanup is in preparation for a patch to add even more options. Discussion: https://postgr.es/m/69a9851035cf0f0477bcc5d742b031a3@oss.nttdata.com
1 parent 4cc832f commit 50e4c28

File tree

1 file changed

+49
-49
lines changed

1 file changed

+49
-49
lines changed

src/bin/scripts/createuser.c

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,29 @@ int
2828
main(int argc, char *argv[])
2929
{
3030
static struct option long_options[] = {
31-
{"host", required_argument, NULL, 'h'},
32-
{"port", required_argument, NULL, 'p'},
33-
{"username", required_argument, NULL, 'U'},
34-
{"role", required_argument, NULL, 'g'},
35-
{"no-password", no_argument, NULL, 'w'},
36-
{"password", no_argument, NULL, 'W'},
37-
{"echo", no_argument, NULL, 'e'},
31+
{"connection-limit", required_argument, NULL, 'c'},
3832
{"createdb", no_argument, NULL, 'd'},
3933
{"no-createdb", no_argument, NULL, 'D'},
40-
{"superuser", no_argument, NULL, 's'},
41-
{"no-superuser", no_argument, NULL, 'S'},
42-
{"createrole", no_argument, NULL, 'r'},
43-
{"no-createrole", no_argument, NULL, 'R'},
34+
{"echo", no_argument, NULL, 'e'},
35+
{"encrypted", no_argument, NULL, 'E'},
36+
{"role", required_argument, NULL, 'g'},
37+
{"host", required_argument, NULL, 'h'},
4438
{"inherit", no_argument, NULL, 'i'},
4539
{"no-inherit", no_argument, NULL, 'I'},
4640
{"login", no_argument, NULL, 'l'},
4741
{"no-login", no_argument, NULL, 'L'},
42+
{"port", required_argument, NULL, 'p'},
43+
{"pwprompt", no_argument, NULL, 'P'},
44+
{"createrole", no_argument, NULL, 'r'},
45+
{"no-createrole", no_argument, NULL, 'R'},
46+
{"superuser", no_argument, NULL, 's'},
47+
{"no-superuser", no_argument, NULL, 'S'},
48+
{"username", required_argument, NULL, 'U'},
49+
{"no-password", no_argument, NULL, 'w'},
50+
{"password", no_argument, NULL, 'W'},
4851
{"replication", no_argument, NULL, 1},
4952
{"no-replication", no_argument, NULL, 2},
5053
{"interactive", no_argument, NULL, 3},
51-
{"connection-limit", required_argument, NULL, 'c'},
52-
{"pwprompt", no_argument, NULL, 'P'},
53-
{"encrypted", no_argument, NULL, 'E'},
5454
{NULL, 0, NULL, 0}
5555
};
5656

@@ -89,49 +89,33 @@ main(int argc, char *argv[])
8989

9090
handle_help_version_opts(argc, argv, "createuser", help);
9191

92-
while ((c = getopt_long(argc, argv, "h:p:U:g:wWedDsSrRiIlLc:PE",
92+
while ((c = getopt_long(argc, argv, "c:dDeEg:h:iIlLp:PrRsSU:wW",
9393
long_options, &optindex)) != -1)
9494
{
9595
switch (c)
9696
{
97-
case 'h':
98-
host = pg_strdup(optarg);
99-
break;
100-
case 'p':
101-
port = pg_strdup(optarg);
102-
break;
103-
case 'U':
104-
username = pg_strdup(optarg);
105-
break;
106-
case 'g':
107-
simple_string_list_append(&roles, optarg);
108-
break;
109-
case 'w':
110-
prompt_password = TRI_NO;
111-
break;
112-
case 'W':
113-
prompt_password = TRI_YES;
114-
break;
115-
case 'e':
116-
echo = true;
97+
case 'c':
98+
if (!option_parse_int(optarg, "-c/--connection-limit",
99+
-1, INT_MAX, &conn_limit))
100+
exit(1);
117101
break;
118102
case 'd':
119103
createdb = TRI_YES;
120104
break;
121105
case 'D':
122106
createdb = TRI_NO;
123107
break;
124-
case 's':
125-
superuser = TRI_YES;
108+
case 'e':
109+
echo = true;
126110
break;
127-
case 'S':
128-
superuser = TRI_NO;
111+
case 'E':
112+
/* no-op, accepted for backward compatibility */
129113
break;
130-
case 'r':
131-
createrole = TRI_YES;
114+
case 'g':
115+
simple_string_list_append(&roles, optarg);
132116
break;
133-
case 'R':
134-
createrole = TRI_NO;
117+
case 'h':
118+
host = pg_strdup(optarg);
135119
break;
136120
case 'i':
137121
inherit = TRI_YES;
@@ -145,16 +129,32 @@ main(int argc, char *argv[])
145129
case 'L':
146130
login = TRI_NO;
147131
break;
148-
case 'c':
149-
if (!option_parse_int(optarg, "-c/--connection-limit",
150-
-1, INT_MAX, &conn_limit))
151-
exit(1);
132+
case 'p':
133+
port = pg_strdup(optarg);
152134
break;
153135
case 'P':
154136
pwprompt = true;
155137
break;
156-
case 'E':
157-
/* no-op, accepted for backward compatibility */
138+
case 'r':
139+
createrole = TRI_YES;
140+
break;
141+
case 'R':
142+
createrole = TRI_NO;
143+
break;
144+
case 's':
145+
superuser = TRI_YES;
146+
break;
147+
case 'S':
148+
superuser = TRI_NO;
149+
break;
150+
case 'U':
151+
username = pg_strdup(optarg);
152+
break;
153+
case 'w':
154+
prompt_password = TRI_NO;
155+
break;
156+
case 'W':
157+
prompt_password = TRI_YES;
158158
break;
159159
case 1:
160160
replication = TRI_YES;

0 commit comments

Comments
 (0)