Skip to content

Commit

Permalink
use getopts for argument evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
milianw committed Sep 2, 2009
1 parent f4760d3 commit b50e411
Showing 1 changed file with 15 additions and 25 deletions.
40 changes: 15 additions & 25 deletions quassellog
Expand Up @@ -52,45 +52,35 @@ function usage {
sqlite3 "$database" "SELECT buffername FROM buffer WHERE buffername != '' ORDER BY buffername" | column
echo
echo " PATTERN a simple pattern, use * for wildcard matching"
echo
# TODO:
echo "NOTE: order of options is not exchangable, i.e. first -u, then -b then pattern..."
}

if [[ "$database" == "" || ! -f "$database" ]]; then
echo "BAD DATABASE: $database"
echo
usage
exit
exit 1
fi

if [[ "$1" == "-u" ]]; then
shift 1
if [[ "$1" == "" ]]; then
usage
exit
while getopts "u:b:" flag
do
if [[ "$flag" == "u" ]]; then
user="$OPTARG"
elif [[ "$flag" == "b" ]]; then
buffer="$OPTARG"
fi
user="$1"
shift 1
fi
done

if [[ "$1" == "-b" ]]; then
shift 1
if [[ "$1" == "" ]]; then
usage
exit
fi
buffer="$1"
shift 1
fi
shift $(($OPTIND - 1))

if [[ "$1" == "" && "$user" == "" && "$buffer" == "" ]]; then
pattern="$1"

if [[ "$pattern" == "" && "$user" == "" && "$buffer" == "" ]]; then
echo "pattern required"
echo
usage
exit
exit 1
fi

pattern="$1"

# escape '
pattern=${pattern//\'/\'\'}
# escape %
Expand Down

0 comments on commit b50e411

Please sign in to comment.