From: Bruce Momjian Date: Thu, 16 Dec 1999 20:10:02 +0000 (+0000) Subject: Hi, X-Git-Tag: REL7_0~1019 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5ca971a18a708341dd49f27c23fec40ea4342d13;p=postgresql Hi, I sending promised patch with: * getopt_long() - for pg_dump (portable) * and "Usage: " changes in scripts in src/bin/ - this changes are cosmetic only, not change any feature ...etc. All PostgreSQL routines (scripts) support now long options and help's output is alike for all scripts and all support -? or --help. Karel Karel Zak http://home.zf.jcu.cz/~zakkr/ --- diff --git a/src/bin/initdb/initdb.sh b/src/bin/initdb/initdb.sh index fd1ac65ecf..4ccd718fc7 100644 --- a/src/bin/initdb/initdb.sh +++ b/src/bin/initdb/initdb.sh @@ -26,7 +26,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.64 1999/12/12 05:57:30 momjian Exp $ +# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.65 1999/12/16 20:09:56 momjian Exp $ # #------------------------------------------------------------------------- @@ -152,27 +152,40 @@ do exit 100 fi ;; + --help) + usage=t + ;; + -\?) + usage=t + ;; *) - echo "Unrecognized option '$1'. Syntax is:" - if [ -z "$MULTIBYTE" ];then - echo "initdb [-t | --template] [-d | --debug]" \ - "[-n | --noclean]" \ - "[-u SUPERUSER | --username=SUPERUSER]" \ - "[-r DATADIR | --pgdata=DATADIR]" \ - "[-l LIBDIR | --pglib=LIBDIR]" - else - echo "initdb [-t | --template] [-d | --debug]" \ - "[-n | --noclean]" \ - "[-u SUPERUSER | --username=SUPERUSER]" \ - "[-r DATADIR | --pgdata=DATADIR]" \ - "[-l LIBDIR | --pglib=LIBDIR]" \ - "[-e ENCODING | --pgencoding=ENCODING]" - fi - exit 100 + echo "Unrecognized option '$1'. Try -? for help." + exit 100 esac shift done +if [ "$usage" ]; then + echo "" + echo "Usage: $CMDNAME [options]" + echo "" + echo " -t, --template " + echo " -d, --debug " + echo " -n, --noclean " + echo " -u SUPERUSER, --username=SUPERUSER " + echo " -r DATADIR, --pgdata=DATADIR " + echo " -l LIBDIR, --pglib=LIBDIR " + + if [ -n "$MULTIBYTE" ]; then + echo " -e ENCODING, --pgencoding=ENCODING" + fi + + echo " -?, --help " + echo "" + + exit 100 +fi + #------------------------------------------------------------------------- # Make sure he told us where to find the Postgres files. #------------------------------------------------------------------------- diff --git a/src/bin/initlocation/initlocation.sh b/src/bin/initlocation/initlocation.sh index 72c106a179..61c5267972 100644 --- a/src/bin/initlocation/initlocation.sh +++ b/src/bin/initlocation/initlocation.sh @@ -12,7 +12,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/initlocation/Attic/initlocation.sh,v 1.2 1998/10/05 02:51:21 thomas Exp $ +# $Header: /cvsroot/pgsql/src/bin/initlocation/Attic/initlocation.sh,v 1.3 1999/12/16 20:09:57 momjian Exp $ # #------------------------------------------------------------------------- @@ -27,21 +27,31 @@ do --location) shift; PGALTDATA="$1"; ;; --username) shift; POSTGRES_SUPERUSERNAME="$1"; ;; + --help) usage=1; ;; -u) shift; POSTGRES_SUPERUSERNAME="$1"; ;; -D) shift; PGALTDATA="$1"; ;; - -*) badparm=$1; usage=1; ;; + -h) usage=t; ;; + -\?) usage=t; ;; + -*) badparm=$1; ;; *) PGALTDATA="$1"; ;; esac shift done if [ -n "$badparm" ]; then - echo "$CMDNAME: Unrecognized parameter '$badparm'" + echo "$CMDNAME: Unrecognized parameter '$badparm'. Try -? for help." + exit 1 fi -if [ -n "$usage" ]; then - echo "Usage: $CMDNAME [-u SUPERUSER] DATADIR" +if [ "$usage" ]; then + echo "" + echo "Usage: $CMDNAME [options] datadir" + echo "" + echo " -u SUPERUSER, --username=SUPERUSER " + echo " -D DATADIR, --location=DATADIR " + echo " -?, --help " + echo "" exit 1 fi diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 39a8be1013..ac2a8daa23 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -21,7 +21,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.125 1999/12/11 00:31:05 momjian Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.126 1999/12/16 20:09:58 momjian Exp $ * * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb * @@ -125,42 +125,54 @@ static void usage(const char *progname) { fprintf(stderr, - "usage: %s [options] dbname\n", progname); - fprintf(stderr, - "\t -a \t\t dump out only the data, no schema\n"); - fprintf(stderr, - "\t -c \t\t clean(drop) schema prior to create\n"); - fprintf(stderr, - "\t -d \t\t dump data as proper insert strings\n"); - fprintf(stderr, - "\t -D \t\t dump data as inserts" - " with attribute names\n"); - fprintf(stderr, - "\t -f filename \t\t script output filename\n"); - fprintf(stderr, - "\t -h hostname \t\t server host name\n"); - fprintf(stderr, - "\t -n \t\t suppress most quotes around identifiers\n"); - fprintf(stderr, - "\t -N \t\t enable most quotes around identifiers\n"); - fprintf(stderr, - "\t -o \t\t dump object id's (oids)\n"); - fprintf(stderr, - "\t -p port \t\t server port number\n"); - fprintf(stderr, - "\t -s \t\t dump out only the schema, no data\n"); - fprintf(stderr, - "\t -t table \t\t dump for this table only\n"); - fprintf(stderr, - "\t -u \t\t use password authentication\n"); + "\nUsage: %s [options] dbname\n\n", progname); + +#ifdef HAVE_GETOPT_LONG fprintf(stderr, - "\t -v \t\t verbose\n"); + + " -a, --data-only dump out only the data, no schema\n" + " -c, --clean clean(drop) schema prior to create\n" + " -d, --insert-proper dump data as proper insert strings\n" + " -D, --insert-attr dump data as inserts with attribute names\n" + " -f, --out file script output filename\n" + " -h, --host hostname server host name\n" + " -n, --no-quotes suppress most quotes around identifiers\n" + " -N, --quotes enable most quotes around identifiers\n" + " -o, --oids dump object id's (oids)\n" + " -p, --port port server port number\n" + " -s, --schema-only dump out only the schema, no data\n" + " -t, --table table dump for this table only\n" + " -u, --password use password authentication\n" + " -v, --verbose verbose\n" + " -x, --no-acl do not dump ACL's (grant/revoke)\n" + " -?, --help show this help message\n" + + ); /* fprintf */ +#else fprintf(stderr, - "\t -x \t\t do not dump ACL's (grant/revoke)\n"); + + " -a dump out only the data, no schema\n" + " -c clean(drop) schema prior to create\n" + " -d dump data as proper insert strings\n" + " -D dump data as inserts with attribute names\n" + " -f filename script output filename\n" + " -h hostname server host name\n" + " -n suppress most quotes around identifiers\n" + " -N enable most quotes around identifiers\n" + " -o dump object id's (oids)\n" + " -p port server port number\n" + " -s dump out only the schema, no data\n" + " -t table dump for this table only\n" + " -u use password authentication\n" + " -v verbose\n" + " -x do not dump ACL's (grant/revoke)\n" + " -? show this help message\n" + + ); /* fprintf */ +#endif + fprintf(stderr, - "\nIf dbname is not supplied, then the DATABASE environment " - "variable value is used.\n"); - fprintf(stderr, "\n"); + "\nIf dbname is not supplied, then the DATABASE environment variable value is used.\n\n"); exit(1); } @@ -534,6 +546,29 @@ main(int argc, char **argv) char password[100]; bool use_password = false; +#ifdef HAVE_GETOPT_LONG + static struct option long_options[] = { + {"data-only", no_argument, NULL, 'a'}, + {"clean", no_argument, NULL, 'c'}, + {"insert-proper",no_argument, NULL, 'd'}, + {"insert-attr", no_argument, NULL, 'D'}, + {"out", required_argument, NULL, 'f'}, + {"to-file", required_argument, NULL, 'f'}, + {"host", required_argument, NULL, 'h'}, + {"no-quotes", no_argument, NULL, 'n'}, + {"quotes", no_argument, NULL, 'N'}, + {"oids", no_argument, NULL, 'o'}, + {"port", required_argument, NULL, 'p'}, + {"schema-only", no_argument, NULL, 's'}, + {"table", required_argument, NULL, 't'}, + {"password", no_argument, NULL, 'u'}, + {"verbose", no_argument, NULL, 'v'}, + {"no-acl", no_argument, NULL, 'x'}, + {"help", no_argument, NULL, '?'}, + }; + int optindex; +#endif + g_verbose = false; force_quotes = true; dropSchema = false; @@ -546,7 +581,11 @@ main(int argc, char **argv) progname = *argv; - while ((c = getopt(argc, argv, "acdDf:h:nNop:st:uvxz")) != EOF) +#ifdef HAVE_GETOPT_LONG + while ((c = getopt_long(argc, argv, "acdDf:h:nNop:st:uvxz?", long_options, &optindex)) != -1) +#else + while ((c = getopt(argc, argv, "acdDf:h:nNop:st:uvxz?")) != -1) +#endif { switch (c) { @@ -627,6 +666,7 @@ main(int argc, char **argv) "%s: The -z option(dump ACLs) is now the default, continuing.\n", progname); break; + case '?': default: usage(progname); break; diff --git a/src/bin/pg_encoding/pg_encoding.c b/src/bin/pg_encoding/pg_encoding.c index e03005338a..ce5a8d8727 100644 --- a/src/bin/pg_encoding/pg_encoding.c +++ b/src/bin/pg_encoding/pg_encoding.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/bin/pg_encoding/Attic/pg_encoding.c,v 1.4 1999/07/17 20:18:20 momjian Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_encoding/Attic/pg_encoding.c,v 1.5 1999/12/16 20:10:00 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -46,5 +46,5 @@ main(int argc, char **argv) static void usage() { - fprintf(stderr, "pg_encoding: encoding_name | encoding_number\n"); + fprintf(stderr, "\nUsage: pg_encoding encoding_name | encoding_number\n\n"); } diff --git a/src/bin/scripts/createdb b/src/bin/scripts/createdb index 800d560cc0..14aad8b890 100644 --- a/src/bin/scripts/createdb +++ b/src/bin/scripts/createdb @@ -11,7 +11,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createdb,v 1.3 1999/12/08 10:29:55 momjian Exp $ +# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createdb,v 1.4 1999/12/16 20:10:02 momjian Exp $ # #------------------------------------------------------------------------- @@ -28,7 +28,6 @@ do case "$1" in --help|-\?) usage=t - break ;; # options passed on to psql --host|-h) @@ -104,11 +103,21 @@ do shift done - if [ "$usage" ]; then - echo "Usage: $CMDNAME [-h server] [-p port] [-D path] \\" - echo " [-E encoding] [-U username] dbname [description]" - exit 0 + echo "" + echo "Usage: $CMDNAME [options] dbname [description]" + echo "" + echo " -h HOSTNAME, --host=HOSTNAME " + echo " -p PORT, --port=PORT " + echo " -U USERNAME, --username=USERNAME " + echo " -W, --password " + echo " -e, --echo " + echo " -q, --quiet " + echo " -D PATH, --location=PATH " + echo " -E ENCODING --encoding=ENCODING " + echo " -?, --help " + echo "" + exit 1 fi diff --git a/src/bin/scripts/createlang.sh b/src/bin/scripts/createlang.sh index 2b39eaa712..18c7c1baa7 100644 --- a/src/bin/scripts/createlang.sh +++ b/src/bin/scripts/createlang.sh @@ -8,7 +8,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createlang.sh,v 1.2 1999/12/07 22:41:44 momjian Exp $ +# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createlang.sh,v 1.3 1999/12/16 20:10:02 momjian Exp $ # #------------------------------------------------------------------------- @@ -51,7 +51,6 @@ do case "$1" in --help|-\?) usage=t - break ;; --list|-l) list=t @@ -127,12 +126,22 @@ do shift done - - -if [ "$usage" ]; then - echo "Usage: $CMDNAME [-h server] [-p port] [-U username] [-d dbname] \\" - echo " [-L|--pglib PGLIB] [langname [dbname]]" - exit 0 +if [ "$usage" ]; then + echo "" + echo "Usage: $CMDNAME [options] [langname [dbname]]" + echo "" + echo " -h HOSTNAME, --host=HOSTNAME " + echo " -p PORT, --port=PORT " + echo " -U USERNAME, --username=USERNAME " + echo " -W, --password " + echo " -d DBNAME, --database=DBNAME " + echo " -e, --echo " + echo " -q, --quiet " + echo " -D PATH, --location=PATH " + echo " -L PGLIB --pglib=PGLIB " + echo " -?, --help " + echo "" + exit 1 fi if [ "$list" ]; then diff --git a/src/bin/scripts/createuser b/src/bin/scripts/createuser index 8eb9d55456..ae4f3dff32 100644 --- a/src/bin/scripts/createuser +++ b/src/bin/scripts/createuser @@ -8,7 +8,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createuser,v 1.3 1999/12/07 22:41:44 momjian Exp $ +# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createuser,v 1.4 1999/12/16 20:10:02 momjian Exp $ # # Note - this should NOT be setuid. # @@ -41,7 +41,6 @@ do case "$1" in --help|-\?) usage=t - break ;; # options passed on to psql --host|-h) @@ -121,15 +120,27 @@ do shift; done - -# Help - -if [ "$usage" ]; then - echo "Usage: $CMDNAME [-h server] [-p port] [-d|-D] [-a|-A] [-P] [-i id] [username]" - exit 0 +if [ "$usage" ]; then + echo "" + echo "Usage: $CMDNAME [options] [username]" + echo "" + echo " -h HOSTNAME, --host=HOSTNAME " + echo " -p PORT, --port=PORT " + echo " -d, --createdb " + echo " -D, --no-createdb " + echo " -a, --adduser " + echo " -A, --no-adduser " + echo " -i SYSID, --sysid=SYSID " + echo " -P, --pwprompt " + echo " -U USERNAME, --username=USERNAME (for connect to db)" + echo " -W, --password (for connect to db)" + echo " -e, --echo " + echo " -q, --quiet " + echo " -?, --help " + echo "" + exit 1 fi - if [ "$SysID" ]; then if [ "$SysID" != "`echo $SysID | sed 's/[^0-9]//g'`" ]; then echo "$CMDNAME: User sysid must be a positive number." diff --git a/src/bin/scripts/dropdb b/src/bin/scripts/dropdb index 8ef22fce84..58b4076ebb 100644 --- a/src/bin/scripts/dropdb +++ b/src/bin/scripts/dropdb @@ -10,7 +10,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropdb,v 1.3 1999/12/07 22:41:44 momjian Exp $ +# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropdb,v 1.4 1999/12/16 20:10:02 momjian Exp $ # #------------------------------------------------------------------------- @@ -96,8 +96,19 @@ done if [ "$usage" ]; then - echo "Usage: $CMDNAME [-h server] [-p port] [-U username] [-i] dbname" - exit 0 + echo "" + echo "Usage: $CMDNAME [options] dbname" + echo "" + echo " -h HOSTNAME, --host=HOSTNAME " + echo " -p PORT, --port=PORT " + echo " -u USERNAME, --username=USERNAME " + echo " -W, --password " + echo " -e, --echo " + echo " -q, --quiet " + echo " -i, --interactive " + echo " -?, --help " + echo "" + exit 1 fi if [ -z "$dbname" ]; then diff --git a/src/bin/scripts/droplang b/src/bin/scripts/droplang index 2ff0ddf30e..8fbfd3b9ec 100644 --- a/src/bin/scripts/droplang +++ b/src/bin/scripts/droplang @@ -8,7 +8,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/droplang,v 1.3 1999/12/07 22:41:44 momjian Exp $ +# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/droplang,v 1.4 1999/12/16 20:10:02 momjian Exp $ # #------------------------------------------------------------------------- @@ -40,7 +40,6 @@ do case "$1" in --help|-\?) usage=t - break ;; --list|-l) list=t @@ -108,10 +107,22 @@ done if [ "$usage" ]; then - echo "Usage: $CMDNAME [-h server] [-p port] [-U username] [-d dbname] [langname [dbname]]" - exit 0 + echo "" + echo "Usage: $CMDNAME [options] [language [dbname]]" + echo "" + echo " -h HOSTNAME, --host=HOSTNAME " + echo " -p PORT, --port=PORT " + echo " -u USERNAME, --username=USERNAME " + echo " -W, --password " + echo " -d DBNAME --database=DBNAME " + echo " -e, --echo " + echo " -q, --quiet " + echo " -?, --help " + echo "" + exit 1 fi + if [ "$list" ]; then psql $PSQLOPT -d "$dbname" -c "SELECT lanname, lanpltrusted, lancompiler FROM pg_language WHERE lanispl = 't'" exit $? diff --git a/src/bin/scripts/dropuser b/src/bin/scripts/dropuser index bec2d9bb21..a5d743eadc 100644 --- a/src/bin/scripts/dropuser +++ b/src/bin/scripts/dropuser @@ -8,7 +8,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropuser,v 1.3 1999/12/07 22:41:44 momjian Exp $ +# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropuser,v 1.4 1999/12/16 20:10:02 momjian Exp $ # # Note - this should NOT be setuid. # @@ -36,7 +36,6 @@ do case "$1" in --help|-\?) usage=t - break ;; # options passed on to psql --host|-h) @@ -96,11 +95,20 @@ do done -# Help - if [ "$usage" ]; then - echo "Usage: $CMDNAME [-h server] [-p port] [-i] [username]" - exit 0 + echo "" + echo "Usage: $CMDNAME [options] [username]" + echo "" + echo " -h HOSTNAME, --host=HOSTNAME " + echo " -p PORT, --port=PORT " + echo " -u USERNAME, --username=USERNAME (for connect to db)" + echo " -W, --password " + echo " -e, --echo " + echo " -q, --quiet " + echo " -i, --interactive " + echo " -?, --help " + echo "" + exit 1 fi # Prompt for username if missing diff --git a/src/bin/scripts/vacuumdb b/src/bin/scripts/vacuumdb index 4998aa44cf..487a2c4fee 100644 --- a/src/bin/scripts/vacuumdb +++ b/src/bin/scripts/vacuumdb @@ -11,7 +11,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/vacuumdb,v 1.3 1999/12/07 22:41:44 momjian Exp $ +# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/vacuumdb,v 1.4 1999/12/16 20:10:02 momjian Exp $ # #------------------------------------------------------------------------- @@ -28,7 +28,6 @@ do case "$1" in --help|-\?) usage=t - break ;; # options passed on to psql --host|-h) @@ -110,11 +109,23 @@ do shift done - -if [ "$usage" ]; then - echo "Usage: $CMDNAME [-h server] [-p port] [-U username] [-d dbname] \\" - echo " [-z|--analyze] [-v|--verbose] [-t|--table 'table[(columns)]'] [dbname]" - exit 0 +if [ "$usage" ]; then + echo "" + echo "Usage: $CMDNAME [options] [dbname]" + echo "" + echo " -h HOSTNAME, --host=HOSTNAME " + echo " -p PORT, --port=PORT " + echo " -u USERNAME, --username=USERNAME " + echo " -W, --password " + echo " -d DBNAME, --database=DBNAME " + echo " -z, --analyze " + echo " -t TABLE[(columns)], --table=TABLE[(columns)]" + echo " -v, --verbose " + echo " -e, --echo " + echo " -q, --quiet " + echo " -?, --help " + echo "" + exit 1 fi if [ -z "$dbname" ]; then