diff options
author | Peter Eisentraut | 2022-12-12 13:33:41 +0000 |
---|---|---|
committer | Peter Eisentraut | 2022-12-12 14:20:00 +0000 |
commit | df8b8968d4095f44acd6de03b4add65f9709b79d (patch) | |
tree | 249063ed382f2d9fc913729de73bac3d915afcab /src/bin/scripts | |
parent | 840ff5f451cd9a391d237fc60894fea7ad82a189 (diff) |
Order getopt arguments
Order the letters in the arguments of getopt() and getopt_long(), as
well as in the subsequent switch statements. In most cases, I used
alphabetical with lower case first. In a few cases, existing
different orders (e.g., upper case first) was kept to reduce the diff
size.
Discussion: https://www.postgresql.org/message-id/flat/3efd0fe8-351b-f836-9122-886002602357%40enterprisedb.com
Diffstat (limited to 'src/bin/scripts')
-rw-r--r-- | src/bin/scripts/clusterdb.c | 38 | ||||
-rw-r--r-- | src/bin/scripts/createdb.c | 44 | ||||
-rw-r--r-- | src/bin/scripts/dropdb.c | 20 | ||||
-rw-r--r-- | src/bin/scripts/dropuser.c | 14 | ||||
-rw-r--r-- | src/bin/scripts/reindexdb.c | 56 | ||||
-rw-r--r-- | src/bin/scripts/vacuumdb.c | 98 |
6 files changed, 132 insertions, 138 deletions
diff --git a/src/bin/scripts/clusterdb.c b/src/bin/scripts/clusterdb.c index df1766679b5..0bda9415803 100644 --- a/src/bin/scripts/clusterdb.c +++ b/src/bin/scripts/clusterdb.c @@ -68,43 +68,43 @@ main(int argc, char *argv[]) handle_help_version_opts(argc, argv, "clusterdb", help); - while ((c = getopt_long(argc, argv, "h:p:U:wWeqd:at:v", long_options, &optindex)) != -1) + while ((c = getopt_long(argc, argv, "ad:eh:p:qt:U:vwW", long_options, &optindex)) != -1) { switch (c) { + case 'a': + alldb = true; + break; + case 'd': + dbname = pg_strdup(optarg); + break; + case 'e': + echo = true; + break; case 'h': host = pg_strdup(optarg); break; case 'p': port = pg_strdup(optarg); break; - case 'U': - username = pg_strdup(optarg); - break; - case 'w': - prompt_password = TRI_NO; - break; - case 'W': - prompt_password = TRI_YES; - break; - case 'e': - echo = true; - break; case 'q': quiet = true; break; - case 'd': - dbname = pg_strdup(optarg); - break; - case 'a': - alldb = true; - break; case 't': simple_string_list_append(&tables, optarg); break; + case 'U': + username = pg_strdup(optarg); + break; case 'v': verbose = true; break; + case 'w': + prompt_password = TRI_NO; + break; + case 'W': + prompt_password = TRI_YES; + break; case 2: maintenance_db = pg_strdup(optarg); break; diff --git a/src/bin/scripts/createdb.c b/src/bin/scripts/createdb.c index a1482df3d98..fa1713a3a0c 100644 --- a/src/bin/scripts/createdb.c +++ b/src/bin/scripts/createdb.c @@ -79,16 +79,37 @@ main(int argc, char *argv[]) handle_help_version_opts(argc, argv, "createdb", help); - while ((c = getopt_long(argc, argv, "h:p:U:wWeO:D:T:E:l:S:", long_options, &optindex)) != -1) + while ((c = getopt_long(argc, argv, "D:eE:h:l:O:p:S:T:U:wW", long_options, &optindex)) != -1) { switch (c) { + case 'D': + tablespace = pg_strdup(optarg); + break; + case 'e': + echo = true; + break; + case 'E': + encoding = pg_strdup(optarg); + break; case 'h': host = pg_strdup(optarg); break; + case 'l': + locale = pg_strdup(optarg); + break; + case 'O': + owner = pg_strdup(optarg); + break; case 'p': port = pg_strdup(optarg); break; + case 'S': + strategy = pg_strdup(optarg); + break; + case 'T': + template = pg_strdup(optarg); + break; case 'U': username = pg_strdup(optarg); break; @@ -98,33 +119,12 @@ main(int argc, char *argv[]) case 'W': prompt_password = TRI_YES; break; - case 'e': - echo = true; - break; - case 'O': - owner = pg_strdup(optarg); - break; - case 'D': - tablespace = pg_strdup(optarg); - break; - case 'T': - template = pg_strdup(optarg); - break; - case 'E': - encoding = pg_strdup(optarg); - break; - case 'S': - strategy = pg_strdup(optarg); - break; case 1: lc_collate = pg_strdup(optarg); break; case 2: lc_ctype = pg_strdup(optarg); break; - case 'l': - locale = pg_strdup(optarg); - break; case 3: maintenance_db = pg_strdup(optarg); break; diff --git a/src/bin/scripts/dropdb.c b/src/bin/scripts/dropdb.c index afc00dac784..3ca5b82ddce 100644 --- a/src/bin/scripts/dropdb.c +++ b/src/bin/scripts/dropdb.c @@ -65,13 +65,22 @@ main(int argc, char *argv[]) handle_help_version_opts(argc, argv, "dropdb", help); - while ((c = getopt_long(argc, argv, "h:p:U:wWeif", long_options, &optindex)) != -1) + while ((c = getopt_long(argc, argv, "efh:ip:U:wW", long_options, &optindex)) != -1) { switch (c) { + case 'e': + echo = true; + break; + case 'f': + force = true; + break; case 'h': host = pg_strdup(optarg); break; + case 'i': + interactive = true; + break; case 'p': port = pg_strdup(optarg); break; @@ -84,15 +93,6 @@ main(int argc, char *argv[]) case 'W': prompt_password = TRI_YES; break; - case 'e': - echo = true; - break; - case 'i': - interactive = true; - break; - case 'f': - force = true; - break; case 0: /* this covers the long options */ break; diff --git a/src/bin/scripts/dropuser.c b/src/bin/scripts/dropuser.c index 82c1f35ab23..d8c77cc8ffe 100644 --- a/src/bin/scripts/dropuser.c +++ b/src/bin/scripts/dropuser.c @@ -62,13 +62,19 @@ main(int argc, char *argv[]) handle_help_version_opts(argc, argv, "dropuser", help); - while ((c = getopt_long(argc, argv, "h:p:U:wWei", long_options, &optindex)) != -1) + while ((c = getopt_long(argc, argv, "eh:ip:U:wW", long_options, &optindex)) != -1) { switch (c) { + case 'e': + echo = true; + break; case 'h': host = pg_strdup(optarg); break; + case 'i': + interactive = true; + break; case 'p': port = pg_strdup(optarg); break; @@ -81,12 +87,6 @@ main(int argc, char *argv[]) case 'W': prompt_password = TRI_YES; break; - case 'e': - echo = true; - break; - case 'i': - interactive = true; - break; case 0: /* this covers the long options */ break; diff --git a/src/bin/scripts/reindexdb.c b/src/bin/scripts/reindexdb.c index 0e93a4eeff0..1fbf924ab3a 100644 --- a/src/bin/scripts/reindexdb.c +++ b/src/bin/scripts/reindexdb.c @@ -109,57 +109,57 @@ main(int argc, char *argv[]) handle_help_version_opts(argc, argv, "reindexdb", help); /* process command-line options */ - while ((c = getopt_long(argc, argv, "h:p:U:wWeqS:d:ast:i:j:v", long_options, &optindex)) != -1) + while ((c = getopt_long(argc, argv, "ad:eh:i:j:qp:sS:t:U:vwW", long_options, &optindex)) != -1) { switch (c) { - case 'h': - host = pg_strdup(optarg); + case 'a': + alldb = true; break; - case 'p': - port = pg_strdup(optarg); + case 'd': + dbname = pg_strdup(optarg); break; - case 'U': - username = pg_strdup(optarg); + case 'e': + echo = true; break; - case 'w': - prompt_password = TRI_NO; + case 'h': + host = pg_strdup(optarg); break; - case 'W': - prompt_password = TRI_YES; + case 'i': + simple_string_list_append(&indexes, optarg); break; - case 'e': - echo = true; + case 'j': + if (!option_parse_int(optarg, "-j/--jobs", 1, INT_MAX, + &concurrentCons)) + exit(1); break; case 'q': quiet = true; break; - case 'S': - simple_string_list_append(&schemas, optarg); - break; - case 'd': - dbname = pg_strdup(optarg); - break; - case 'a': - alldb = true; + case 'p': + port = pg_strdup(optarg); break; case 's': syscatalog = true; break; + case 'S': + simple_string_list_append(&schemas, optarg); + break; case 't': simple_string_list_append(&tables, optarg); break; - case 'i': - simple_string_list_append(&indexes, optarg); - break; - case 'j': - if (!option_parse_int(optarg, "-j/--jobs", 1, INT_MAX, - &concurrentCons)) - exit(1); + case 'U': + username = pg_strdup(optarg); break; case 'v': verbose = true; break; + case 'w': + prompt_password = TRI_NO; + break; + case 'W': + prompt_password = TRI_YES; + break; case 1: concurrently = true; break; diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c index 0482aa9e885..272e37d290c 100644 --- a/src/bin/scripts/vacuumdb.c +++ b/src/bin/scripts/vacuumdb.c @@ -155,82 +155,76 @@ main(int argc, char *argv[]) handle_help_version_opts(argc, argv, "vacuumdb", help); - while ((c = getopt_long(argc, argv, "h:p:U:wWeqd:zZFat:fvj:P:n:N:", long_options, &optindex)) != -1) + while ((c = getopt_long(argc, argv, "ad:efFh:j:n:N:p:P:qt:U:vwWzZ", long_options, &optindex)) != -1) { switch (c) { - case 'h': - host = pg_strdup(optarg); - break; - case 'p': - port = pg_strdup(optarg); - break; - case 'U': - username = pg_strdup(optarg); - break; - case 'w': - prompt_password = TRI_NO; - break; - case 'W': - prompt_password = TRI_YES; - break; - case 'e': - echo = true; - break; - case 'q': - quiet = true; + case 'a': + objfilter |= OBJFILTER_ALL_DBS; break; case 'd': objfilter |= OBJFILTER_DATABASE; dbname = pg_strdup(optarg); break; - case 'z': - vacopts.and_analyze = true; + case 'e': + echo = true; break; - case 'Z': - vacopts.analyze_only = true; + case 'f': + vacopts.full = true; break; case 'F': vacopts.freeze = true; break; - case 'a': - objfilter |= OBJFILTER_ALL_DBS; - break; - case 't': - { - objfilter |= OBJFILTER_TABLE; - simple_string_list_append(&objects, optarg); - tbl_count++; - break; - } - case 'f': - vacopts.full = true; - break; - case 'v': - vacopts.verbose = true; + case 'h': + host = pg_strdup(optarg); break; case 'j': if (!option_parse_int(optarg, "-j/--jobs", 1, INT_MAX, &concurrentCons)) exit(1); break; + case 'n': + objfilter |= OBJFILTER_SCHEMA; + simple_string_list_append(&objects, optarg); + break; + case 'N': + objfilter |= OBJFILTER_SCHEMA_EXCLUDE; + simple_string_list_append(&objects, optarg); + break; + case 'p': + port = pg_strdup(optarg); + break; case 'P': if (!option_parse_int(optarg, "-P/--parallel", 0, INT_MAX, &vacopts.parallel_workers)) exit(1); break; - case 'n': - { - objfilter |= OBJFILTER_SCHEMA; - simple_string_list_append(&objects, optarg); - break; - } - case 'N': - { - objfilter |= OBJFILTER_SCHEMA_EXCLUDE; - simple_string_list_append(&objects, optarg); - break; - } + case 'q': + quiet = true; + break; + case 't': + objfilter |= OBJFILTER_TABLE; + simple_string_list_append(&objects, optarg); + tbl_count++; + break; + case 'U': + username = pg_strdup(optarg); + break; + case 'v': + vacopts.verbose = true; + break; + case 'w': + prompt_password = TRI_NO; + break; + case 'W': + prompt_password = TRI_YES; + break; + case 'z': + vacopts.and_analyze = true; + break; + case 'Z': + vacopts.analyze_only = true; + break; case 2: maintenance_db = pg_strdup(optarg); break; |