Commit 5ca971a1 authored by Bruce Momjian's avatar Bruce Momjian

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 <zakkr@zf.jcu.cz>              http://home.zf.jcu.cz/~zakkr/
parent cf374feb
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
# #
# #
# IDENTIFICATION # 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 ...@@ -152,27 +152,40 @@ do
exit 100 exit 100
fi fi
;; ;;
--help)
usage=t
;;
-\?)
usage=t
;;
*) *)
echo "Unrecognized option '$1'. Syntax is:" echo "Unrecognized option '$1'. Try -? for help."
if [ -z "$MULTIBYTE" ];then exit 100
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
esac esac
shift shift
done 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. # Make sure he told us where to find the Postgres files.
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
# #
# #
# IDENTIFICATION # 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 ...@@ -27,21 +27,31 @@ do
--location) shift; PGALTDATA="$1"; ;; --location) shift; PGALTDATA="$1"; ;;
--username) shift; POSTGRES_SUPERUSERNAME="$1"; ;; --username) shift; POSTGRES_SUPERUSERNAME="$1"; ;;
--help) usage=1; ;;
-u) shift; POSTGRES_SUPERUSERNAME="$1"; ;; -u) shift; POSTGRES_SUPERUSERNAME="$1"; ;;
-D) shift; PGALTDATA="$1"; ;; -D) shift; PGALTDATA="$1"; ;;
-*) badparm=$1; usage=1; ;; -h) usage=t; ;;
-\?) usage=t; ;;
-*) badparm=$1; ;;
*) PGALTDATA="$1"; ;; *) PGALTDATA="$1"; ;;
esac esac
shift shift
done done
if [ -n "$badparm" ]; then if [ -n "$badparm" ]; then
echo "$CMDNAME: Unrecognized parameter '$badparm'" echo "$CMDNAME: Unrecognized parameter '$badparm'. Try -? for help."
exit 1
fi fi
if [ -n "$usage" ]; then if [ "$usage" ]; then
echo "Usage: $CMDNAME [-u SUPERUSER] DATADIR" echo ""
echo "Usage: $CMDNAME [options] datadir"
echo ""
echo " -u SUPERUSER, --username=SUPERUSER "
echo " -D DATADIR, --location=DATADIR "
echo " -?, --help "
echo ""
exit 1 exit 1
fi fi
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
* *
* *
* IDENTIFICATION * 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 * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
* *
...@@ -125,42 +125,54 @@ static void ...@@ -125,42 +125,54 @@ static void
usage(const char *progname) usage(const char *progname)
{ {
fprintf(stderr, fprintf(stderr,
"usage: %s [options] dbname\n", progname); "\nUsage: %s [options] dbname\n\n", progname);
fprintf(stderr,
"\t -a \t\t dump out only the data, no schema\n"); #ifdef HAVE_GETOPT_LONG
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");
fprintf(stderr, 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, 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, fprintf(stderr,
"\nIf dbname is not supplied, then the DATABASE environment " "\nIf dbname is not supplied, then the DATABASE environment variable value is used.\n\n");
"variable value is used.\n");
fprintf(stderr, "\n");
exit(1); exit(1);
} }
...@@ -534,6 +546,29 @@ main(int argc, char **argv) ...@@ -534,6 +546,29 @@ main(int argc, char **argv)
char password[100]; char password[100];
bool use_password = false; 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; g_verbose = false;
force_quotes = true; force_quotes = true;
dropSchema = false; dropSchema = false;
...@@ -546,7 +581,11 @@ main(int argc, char **argv) ...@@ -546,7 +581,11 @@ main(int argc, char **argv)
progname = *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) switch (c)
{ {
...@@ -627,6 +666,7 @@ main(int argc, char **argv) ...@@ -627,6 +666,7 @@ main(int argc, char **argv)
"%s: The -z option(dump ACLs) is now the default, continuing.\n", "%s: The -z option(dump ACLs) is now the default, continuing.\n",
progname); progname);
break; break;
case '?':
default: default:
usage(progname); usage(progname);
break; break;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -46,5 +46,5 @@ main(int argc, char **argv)
static void static void
usage() usage()
{ {
fprintf(stderr, "pg_encoding: encoding_name | encoding_number\n"); fprintf(stderr, "\nUsage: pg_encoding encoding_name | encoding_number\n\n");
} }
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# #
# IDENTIFICATION # 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 ...@@ -28,7 +28,6 @@ do
case "$1" in case "$1" in
--help|-\?) --help|-\?)
usage=t usage=t
break
;; ;;
# options passed on to psql # options passed on to psql
--host|-h) --host|-h)
...@@ -104,11 +103,21 @@ do ...@@ -104,11 +103,21 @@ do
shift shift
done done
if [ "$usage" ]; then if [ "$usage" ]; then
echo "Usage: $CMDNAME [-h server] [-p port] [-D path] \\" echo ""
echo " [-E encoding] [-U username] dbname [description]" echo "Usage: $CMDNAME [options] dbname [description]"
exit 0 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 fi
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
# #
# #
# IDENTIFICATION # 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 ...@@ -51,7 +51,6 @@ do
case "$1" in case "$1" in
--help|-\?) --help|-\?)
usage=t usage=t
break
;; ;;
--list|-l) --list|-l)
list=t list=t
...@@ -127,12 +126,22 @@ do ...@@ -127,12 +126,22 @@ do
shift shift
done done
if [ "$usage" ]; then
echo ""
if [ "$usage" ]; then echo "Usage: $CMDNAME [options] [langname [dbname]]"
echo "Usage: $CMDNAME [-h server] [-p port] [-U username] [-d dbname] \\" echo ""
echo " [-L|--pglib PGLIB] [langname [dbname]]" echo " -h HOSTNAME, --host=HOSTNAME "
exit 0 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 fi
if [ "$list" ]; then if [ "$list" ]; then
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
# #
# #
# IDENTIFICATION # 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. # Note - this should NOT be setuid.
# #
...@@ -41,7 +41,6 @@ do ...@@ -41,7 +41,6 @@ do
case "$1" in case "$1" in
--help|-\?) --help|-\?)
usage=t usage=t
break
;; ;;
# options passed on to psql # options passed on to psql
--host|-h) --host|-h)
...@@ -121,15 +120,27 @@ do ...@@ -121,15 +120,27 @@ do
shift; shift;
done done
if [ "$usage" ]; then
# Help echo ""
echo "Usage: $CMDNAME [options] [username]"
if [ "$usage" ]; then echo ""
echo "Usage: $CMDNAME [-h server] [-p port] [-d|-D] [-a|-A] [-P] [-i id] [username]" echo " -h HOSTNAME, --host=HOSTNAME "
exit 0 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 fi
if [ "$SysID" ]; then if [ "$SysID" ]; then
if [ "$SysID" != "`echo $SysID | sed 's/[^0-9]//g'`" ]; then if [ "$SysID" != "`echo $SysID | sed 's/[^0-9]//g'`" ]; then
echo "$CMDNAME: User sysid must be a positive number." echo "$CMDNAME: User sysid must be a positive number."
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# #
# #
# IDENTIFICATION # 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 ...@@ -96,8 +96,19 @@ done
if [ "$usage" ]; then if [ "$usage" ]; then
echo "Usage: $CMDNAME [-h server] [-p port] [-U username] [-i] dbname" echo ""
exit 0 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 fi
if [ -z "$dbname" ]; then if [ -z "$dbname" ]; then
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
# #
# #
# IDENTIFICATION # 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 ...@@ -40,7 +40,6 @@ do
case "$1" in case "$1" in
--help|-\?) --help|-\?)
usage=t usage=t
break
;; ;;
--list|-l) --list|-l)
list=t list=t
...@@ -108,10 +107,22 @@ done ...@@ -108,10 +107,22 @@ done
if [ "$usage" ]; then if [ "$usage" ]; then
echo "Usage: $CMDNAME [-h server] [-p port] [-U username] [-d dbname] [langname [dbname]]" echo ""
exit 0 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 fi
if [ "$list" ]; then if [ "$list" ]; then
psql $PSQLOPT -d "$dbname" -c "SELECT lanname, lanpltrusted, lancompiler FROM pg_language WHERE lanispl = 't'" psql $PSQLOPT -d "$dbname" -c "SELECT lanname, lanpltrusted, lancompiler FROM pg_language WHERE lanispl = 't'"
exit $? exit $?
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
# #
# #
# IDENTIFICATION # 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. # Note - this should NOT be setuid.
# #
...@@ -36,7 +36,6 @@ do ...@@ -36,7 +36,6 @@ do
case "$1" in case "$1" in
--help|-\?) --help|-\?)
usage=t usage=t
break
;; ;;
# options passed on to psql # options passed on to psql
--host|-h) --host|-h)
...@@ -96,11 +95,20 @@ do ...@@ -96,11 +95,20 @@ do
done done
# Help
if [ "$usage" ]; then if [ "$usage" ]; then
echo "Usage: $CMDNAME [-h server] [-p port] [-i] [username]" echo ""
exit 0 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 fi
# Prompt for username if missing # Prompt for username if missing
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# #
# IDENTIFICATION # 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 ...@@ -28,7 +28,6 @@ do
case "$1" in case "$1" in
--help|-\?) --help|-\?)
usage=t usage=t
break
;; ;;
# options passed on to psql # options passed on to psql
--host|-h) --host|-h)
...@@ -110,11 +109,23 @@ do ...@@ -110,11 +109,23 @@ do
shift shift
done done
if [ "$usage" ]; then
if [ "$usage" ]; then echo ""
echo "Usage: $CMDNAME [-h server] [-p port] [-U username] [-d dbname] \\" echo "Usage: $CMDNAME [options] [dbname]"
echo " [-z|--analyze] [-v|--verbose] [-t|--table 'table[(columns)]'] [dbname]" echo ""
exit 0 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 fi
if [ -z "$dbname" ]; then if [ -z "$dbname" ]; then
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment