Re: More problem with scripts - Mailing list pgsql-hackers

From Bruce Momjian
Subject Re: More problem with scripts
Date
Msg-id 200201040534.g045YrI26643@candle.pha.pa.us
Whole thread Raw
In response to Re: More problem with scripts  (Brent Verner <brent@rcfile.org>)
Responses Re: More problem with scripts  (Brent Verner <brent@rcfile.org>)
List pgsql-hackers
Brent Verner wrote:
> [2002-01-03 23:33] Peter Eisentraut said:
> | > Brent Verner wrote:
> | > > [2002-01-03 14:19] Bruce Momjian said:
> | > > |
> | > > | Actually, we can just do:
>
> | > > +1
> | > >
> | > >   I can't see a reason to /not/ fix something this simple for the 7.2
> | > > release.  In general, I think it's best to fix things like this[1]
> | > > "on sight" as opposed to queueing them in TODO where they /might/ sit
> | > > untouched through another release cycle.
> | > >
> | > > [1] meaning problems that require little effort to fix, and whose
> | > >     solutions are /very/ localized.
> | >
> | > OK, one more +1 and I will get to it.
> |
> | -4

OK, here's the patch.  Seems createdb wasn't properly handling the db
comment (arg code now similar to createlang), createlang dbname being
optional wasn't documented in --help, and vacuumdb wasn't handlling an
optional dbname.  I added the required checks so extra arguments report
a failure:

    $ dropdb lkjas asdfljk test
    dropdb: invalid option: asdfljk
    Try 'dropdb --help' for more information.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
Index: doc/src/sgml/ref/vacuumdb.sgml
===================================================================
RCS file: /cvsroot/pgsql/doc/src/sgml/ref/vacuumdb.sgml,v
retrieving revision 1.20
diff -c -r1.20 vacuumdb.sgml
*** doc/src/sgml/ref/vacuumdb.sgml    2001/12/08 03:24:40    1.20
--- doc/src/sgml/ref/vacuumdb.sgml    2002/01/04 05:23:04
***************
*** 23,33 ****
    <cmdsynopsis>
     <command>vacuumdb</command>
     <arg rep="repeat"><replaceable>connection-options</replaceable></arg>
!    <arg><arg>-d</arg> <replaceable>dbname</replaceable></arg>
     <group><arg>--full</arg><arg>-f</arg></group>
     <group><arg>--verbose</arg><arg>-v</arg></group>
     <group><arg>--analyze</arg><arg>-z</arg></group>
!    <arg>--table '<replaceable>table</replaceable>
      <arg>( <replaceable class="parameter">column</replaceable> [,...] )</arg>'
     </arg>
     <sbr>
--- 23,33 ----
    <cmdsynopsis>
     <command>vacuumdb</command>
     <arg rep="repeat"><replaceable>connection-options</replaceable></arg>
!    <arg><replaceable>dbname</replaceable></arg>
     <group><arg>--full</arg><arg>-f</arg></group>
     <group><arg>--verbose</arg><arg>-v</arg></group>
     <group><arg>--analyze</arg><arg>-z</arg></group>
!    <arg>--table | -t '<replaceable>table</replaceable>
      <arg>( <replaceable class="parameter">column</replaceable> [,...] )</arg>'
     </arg>
     <sbr>
Index: src/bin/scripts/createdb
===================================================================
RCS file: /cvsroot/pgsql/src/bin/scripts/createdb,v
retrieving revision 1.18
diff -c -r1.18 createdb
*** src/bin/scripts/createdb    2001/09/30 22:17:51    1.18
--- src/bin/scripts/createdb    2002/01/04 05:23:05
***************
*** 104,114 ****
          exit 1
          ;;
      *)
!         if [ -z "$dbname" ]; then
!             dbname="$1"
!         else
              dbcomment="$1"
          fi
          ;;
      esac
      shift
--- 104,120 ----
          exit 1
          ;;
      *)
!         dbname="$1"
!         if [ "$2" ]
!         then
!             shift
              dbcomment="$1"
          fi
+         if [ "$#" -ne 1 ]; then
+             echo "$CMDNAME: invalid option: $2" 1>&2
+                     echo "Try '$CMDNAME --help' for more information." 1>&2
+             exit 1
+         fi
          ;;
      esac
      shift
***************
*** 118,124 ****
          echo "$CMDNAME creates a PostgreSQL database."
          echo
      echo "Usage:"
!         echo "  $CMDNAME [options] dbname [description]"
          echo
      echo "Options:"
      echo "  -D, --location=PATH             Alternative place to store the database"
--- 124,130 ----
          echo "$CMDNAME creates a PostgreSQL database."
          echo
      echo "Usage:"
!         echo "  $CMDNAME [options] [dbname] [description]"
          echo
      echo "Options:"
      echo "  -D, --location=PATH             Alternative place to store the database"
Index: src/bin/scripts/createlang.sh
===================================================================
RCS file: /cvsroot/pgsql/src/bin/scripts/createlang.sh,v
retrieving revision 1.32
diff -c -r1.32 createlang.sh
*** src/bin/scripts/createlang.sh    2002/01/03 05:30:04    1.32
--- src/bin/scripts/createlang.sh    2002/01/04 05:23:05
***************
*** 116,121 ****
--- 116,126 ----
              fi
          else    dbname="$1"
          fi
+         if [ "$#" -ne 1 ]; then
+             echo "$CMDNAME: invalid option: $2" 1>&2
+                     echo "Try '$CMDNAME --help' for more information." 1>&2
+             exit 1
+         fi
                  ;;
      esac
      shift
Index: src/bin/scripts/createuser
===================================================================
RCS file: /cvsroot/pgsql/src/bin/scripts/createuser,v
retrieving revision 1.22
diff -c -r1.22 createuser
*** src/bin/scripts/createuser    2001/09/30 22:17:51    1.22
--- src/bin/scripts/createuser    2002/01/04 05:23:05
***************
*** 123,128 ****
--- 123,133 ----
          ;;
           *)
          NewUser="$1"
+         if [ "$#" -ne 1 ]; then
+             echo "$CMDNAME: invalid option: $2" 1>&2
+                     echo "Try '$CMDNAME --help' for more information." 1>&2
+             exit 1
+         fi
          ;;
      esac
      shift;
Index: src/bin/scripts/dropdb
===================================================================
RCS file: /cvsroot/pgsql/src/bin/scripts/dropdb,v
retrieving revision 1.13
diff -c -r1.13 dropdb
*** src/bin/scripts/dropdb    2001/09/30 22:17:51    1.13
--- src/bin/scripts/dropdb    2002/01/04 05:23:05
***************
*** 89,94 ****
--- 89,99 ----
          ;;
       *)
          dbname="$1"
+         if [ "$#" -ne 1 ]; then
+             echo "$CMDNAME: invalid option: $2" 1>&2
+                     echo "Try '$CMDNAME --help' for more information." 1>&2
+             exit 1
+         fi
          ;;
      esac
      shift
Index: src/bin/scripts/droplang
===================================================================
RCS file: /cvsroot/pgsql/src/bin/scripts/droplang,v
retrieving revision 1.20
diff -c -r1.20 droplang
*** src/bin/scripts/droplang    2002/01/03 08:53:00    1.20
--- src/bin/scripts/droplang    2002/01/04 05:23:05
***************
*** 105,110 ****
--- 105,115 ----
              fi
          else    dbname="$1"
          fi
+         if [ "$#" -ne 1 ]; then
+             echo "$CMDNAME: invalid option: $2" 1>&2
+                     echo "Try '$CMDNAME --help' for more information." 1>&2
+             exit 1
+         fi
                  ;;
      esac
      shift
Index: src/bin/scripts/dropuser
===================================================================
RCS file: /cvsroot/pgsql/src/bin/scripts/dropuser,v
retrieving revision 1.14
diff -c -r1.14 dropuser
*** src/bin/scripts/dropuser    2001/09/30 22:17:51    1.14
--- src/bin/scripts/dropuser    2002/01/04 05:23:05
***************
*** 91,96 ****
--- 91,101 ----
          ;;
           *)
          DelUser="$1"
+         if [ "$#" -ne 1 ]; then
+             echo "$CMDNAME: invalid option: $2" 1>&2
+                     echo "Try '$CMDNAME --help' for more information." 1>&2
+             exit 1
+         fi
          ;;
      esac
      shift;
Index: src/bin/scripts/vacuumdb
===================================================================
RCS file: /cvsroot/pgsql/src/bin/scripts/vacuumdb,v
retrieving revision 1.19
diff -c -r1.19 vacuumdb
*** src/bin/scripts/vacuumdb    2001/09/30 22:17:51    1.19
--- src/bin/scripts/vacuumdb    2002/01/04 05:23:05
***************
*** 112,117 ****
--- 112,122 ----
          ;;
      *)
          dbname="$1"
+         if [ "$#" -ne 1 ]; then
+             echo "$CMDNAME: invalid option: $2" 1>&2
+                     echo "Try '$CMDNAME --help' for more information." 1>&2
+             exit 1
+         fi
          ;;
      esac
      shift
***************
*** 151,159 ****
      dbname=`${PATHNAME}psql $PSQLOPT -q -t -A -d template1 -c 'SELECT datname FROM pg_database WHERE datallowconn'`

  elif [ -z "$dbname" ]; then
!     echo "$CMDNAME: missing required argument: database name" 1>&2
!         echo "Try '$CMDNAME -?' for help." 1>&2
!     exit 1
  fi

  for db in $dbname
--- 156,167 ----
      dbname=`${PATHNAME}psql $PSQLOPT -q -t -A -d template1 -c 'SELECT datname FROM pg_database WHERE datallowconn'`

  elif [ -z "$dbname" ]; then
!         if [ "$PGUSER" ]; then
!                 dbname="$PGUSER"
!         else
!                 dbname=`${PATHNAME}pg_id -u -n`
!         fi
!         [ "$?" -ne 0 ] && exit 1
  fi

  for db in $dbname

pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: LWLock contention: I think I understand the problem
Next
From: Bruce Momjian
Date:
Subject: Re: PGSQL - FAQ 4.1