]> xenbits.xensource.com Git - people/royger/osstest.git/commitdiff
sa-init-db: Fix argument parsing
authorIan Jackson <ian.jackson@eu.citrix.com>
Wed, 24 Oct 2018 10:24:36 +0000 (11:24 +0100)
committerIan Jackson <ian.jackson@eu.citrix.com>
Wed, 24 Oct 2018 10:24:36 +0000 (11:24 +0100)
It claimed to have a default db name, but it didn't.  Rework the
option parsing to make the usage message true.  (That saves me typing
  sa-init-db standalone
and getting bizarre errors as sqlite tries to treat the shell script
`standalone' as if it were a database file.)

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
sa-init-db

index bd9aa4a4dfe97ed2eb66315a0f994fe05178779a..2c97aaba85bf5b992bec85ac687a3d58a9ec68fb 100755 (executable)
 
 set -e -o posix
 
-usage(){
-       cat <<END
+badusage(){
+       cat <<END >&2
 usage: ./sa-init-db [database]
 END
+       exit 127
 }
 
-if [ $# -ne 1 ] ; then
-       usage >&2
-       exit 1
-fi
-
-db="$1"
+case "$#.$*" in
+0.)    db=standalone.db        ;;
+1.-*)  badusage                ;;
+1.*)   db="$1"                 ;;
+*)     badusage                ;;
+esac
 
 sqlite3 "$db" <<END
        CREATE TABLE flights (