Skip to content

Commit

Permalink
Gardening the option handling
Browse files Browse the repository at this point in the history
  • Loading branch information
zwets committed Jan 26, 2021
1 parent e90da8b commit ea69d23
Show file tree
Hide file tree
Showing 17 changed files with 89 additions and 216 deletions.
2 changes: 1 addition & 1 deletion uf
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ while [ $# -ne 0 -a "$(expr "$1" : '\(.\)..*')" = "-" ]; do
-h|--help) usage_exit 0 ;;
*) usage_exit ;;
esac
shift
shift || usage_exit
done

if [ -n "$REVERT" ]; then
Expand Down
18 changes: 5 additions & 13 deletions uf-bare
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,12 @@ unset HDRSFILE FORCE

while [ $# -ne 0 -a "$(expr "$1" : '\(.\)..*')" = "-" ]; do
case $1 in
-w) shift
[ $# -ge 1 ] || usage_exit
HDRSFILE="$1"
;;
-f|--force)
FORCE="yes"
;;
--help)
usage_exit 0
;;
*) usage_exit
;;
-w) shift; HDRSFILE="$1" ;;
-f|--force) FORCE="yes" ;;
--help) usage_exit 0 ;;
*) usage_exit ;;
esac
shift
shift || usage_exit
done

# Check options validity
Expand Down
21 changes: 6 additions & 15 deletions uf-circut
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,13 @@ MARK=0

while [ $# -ne 0 -a "$(expr "$1" : '\(.\)..*')" = "-" ]; do
case $1 in
-m|--mark)
MARK=1
;;
-z|--zero)
ZERO=1
;;
-q|--quiet)
QUIET=1
;;
-h|--help)
usage_exit 0
;;
*) usage_exit
;;
-m|--mark) MARK=1 ;;
-z|--zero) ZERO=1 ;;
-q|--quiet) QUIET=1 ;;
-h|--help) usage_exit 0 ;;
*) usage_exit ;;
esac
shift
shift || usage_exit
done

# Parse the cut specification - arrr walk the regex plank matey
Expand Down
25 changes: 7 additions & 18 deletions uf-cut
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,14 @@ MARK=0

while [ $# -ne 0 -a "$(expr "$1" : '\(.\)..*')" = "-" ]; do
case $1 in
-m|--mark)
MARK=1
;;
-c|--clip)
CLIP=1
;;
-q|--quiet)
QUIET=1
;;
-z|--zero)
ZERO=1
;;
-h|--help)
usage_exit 0
;;
*) usage_exit
;;
-m|--mark) MARK=1 ;;
-c|--clip) CLIP=1 ;;
-q|--quiet) QUIET=1 ;;
-z|--zero) ZERO=1 ;;
-h|--help) usage_exit 0 ;;
*) usage_exit ;;
esac
shift
shift || usage_exit
done

# Parse the cut specification - arrr walk the regex plank matey
Expand Down
14 changes: 4 additions & 10 deletions uf-dress
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,11 @@ unset HDRSFILE

while [ $# -ne 0 -a "$(expr "$1" : '\(.\)..*')" = "-" ]; do
case $1 in
-r) shift
[ $# -ge 1 ] || usage_exit
HDRSFILE="$1"
;;
--help)
usage_exit 0
;;
*) usage_exit
;;
-r) shift; HDRSFILE="$1" ;;
--help) usage_exit 0 ;;
*) usage_exit ;;
esac
shift
shift || usage_exit
done

# Check options validity
Expand Down
17 changes: 5 additions & 12 deletions uf-drop
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,12 @@ MARK=0

while [ $# -ne 0 -a "$(expr "$1" : '\(.\)..*')" = "-" ]; do
case $1 in
-m|--mark)
MARK=1
;;
-b|--but)
BUT=1
;;
-h|--help)
usage_exit 0
;;
*) usage_exit
;;
-m|--mark) MARK=1 ;;
-b|--but) BUT=1 ;;
-h|--help) usage_exit 0 ;;
*) usage_exit ;;
esac
shift
shift || usage_exit
done

# Check first argument is positive number
Expand Down
21 changes: 6 additions & 15 deletions uf-freqs
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,13 @@ TOTALS=0

while [ $# -ne 0 -a "$(expr "$1" : '\(.\)..*')" = "-" ]; do
case $1 in
-b|--bare)
BARE=1
;;
-l|--length*)
LENGTH_ONLY=1
;;
-t|--totals)
TOTALS=1
;;
-h|--help)
usage_exit 0
;;
*) usage_exit
;;
-b|--bare) BARE=1 ;;
-l|--length*) LENGTH_ONLY=1 ;;
-t|--totals) TOTALS=1 ;;
-h|--help) usage_exit 0 ;;
*) usage_exit ;;
esac
shift
shift || usage_exit
done

gawk -bO -v P="$(basename "$0")" -v BARE=$BARE -v LENGTH_ONLY=$LENGTH_ONLY -v TOTALS=$TOTALS '
Expand Down
18 changes: 5 additions & 13 deletions uf-hash
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,12 @@ Usage: $(basename $0) [OPTIONS] [FILE ...]
unset REORDERABLE
while [ $# -ne 0 -a "$(expr "$1" : '\(.\)..*')" = "-" ]; do
case $1 in
--algo=*)
ALGO=${1#--algo=}
;;
-a|--algo*)
shift
ALGO=$1
;;
-h|--help)
usage_exit 0
;;
*) usage_exit
;;
--algo=*) ALGO=${1#--algo=} ;;
-a|--algo*) shift; ALGO=$1 ;;
-h|--help) usage_exit 0 ;;
*) usage_exit ;;
esac
shift
shift || usage_exit
done

# Check options and arguments
Expand Down
9 changes: 3 additions & 6 deletions uf-headers
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,10 @@ Usage: $(basename $0) [OPTIONS] [FILE ...]

while [ $# -ne 0 -a "$(expr "$1" : '\(.\)..*')" = "-" ]; do
case $1 in
--help)
usage_exit 0
;;
*) usage_exit
;;
--help) usage_exit 0 ;;
*) usage_exit ;;
esac
shift
shift || usage_exit
done

gawk -bO 'NR%2==1' "$@"
Expand Down
13 changes: 4 additions & 9 deletions uf-map
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,11 @@ Usage: $(basename $0) [OPTIONS] OPERATION [FILE ...]
unset TITLES
while [ $# -ne 0 -a "$(expr "$1" : '\(.\)..*')" = "-" ]; do
case $1 in
-t|--title*)
TITLES=1
;;
-h|--help)
usage_exit 0
;;
*) usage_exit
;;
-t|--title*) TITLES=1 ;;
-h|--help) usage_exit 0 ;;
*) usage_exit ;;
esac
shift
shift || usage_exit
done

# Parse arguments
Expand Down
39 changes: 9 additions & 30 deletions uf-random
Original file line number Diff line number Diff line change
Expand Up @@ -53,37 +53,16 @@ Usage: $(basename $0) [OPTIONS] [CHARS]

while [ $# -ne 0 -a "$(expr "$1" : '\(.\)..*')" = "-" ]; do
case $1 in
--count=*)
SEQ_COUNT=${1#--count=}
;;
-c|--count)
shift
[ $# -ge 1 ] || usage_exit
SEQ_COUNT=$1
;;
--length=*)
SEQ_LENGTH=${1#--length=}
;;
-l|--length)
shift
[ $# -ge 1 ] || usage_exit
SEQ_LENGTH=$1
;;
--range=*)
RANGE=${1#--range=}
;;
-r|--range)
shift
[ $# -ge 1 ] || usage_exit
RANGE=$1
;;
--help)
usage_exit 0
;;
*) usage_exit
;;
--count=*) SEQ_COUNT=${1#--count=} ;;
-c|--count) shift; SEQ_COUNT=$1 ;;
--length=*) SEQ_LENGTH=${1#--length=} ;;
-l|--length) shift; SEQ_LENGTH=$1 ;;
--range=*) RANGE=${1#--range=} ;;
-r|--range) shift; RANGE=$1 ;;
--help) usage_exit 0 ;;
*) usage_exit ;;
esac
shift
shift || usage_exit
done

# Parse arguments
Expand Down
21 changes: 6 additions & 15 deletions uf-rc
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,13 @@ MARK=0

while [ $# -ne 0 -a "$(expr "$1" : '\(.\)..*')" = "-" ]; do
case $1 in
-r|--reverse-only)
COMPLEMENT=0
;;
-c|--complement-only)
REVERSE=0
;;
-m|--mark*)
MARK=1
;;
--help)
usage_exit 0
;;
*) usage_exit
;;
-r|--reverse-only) COMPLEMENT=0 ;;
-c|--complement-only) REVERSE=0 ;;
-m|--mark*) MARK=1 ;;
--help) usage_exit 0 ;;
*) usage_exit ;;
esac
shift
shift || usage_exit
done

# Do the work
Expand Down
12 changes: 6 additions & 6 deletions uf-select
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ unset NTH SEQID REGEX
while [ $# -ne 0 -a "$(expr "$1" : '\(.\)..*')" = "-" ]; do
case $1 in
--nth=*) NTH=${1#--nth=} ;;
-n|--nth) shift; [ $# -ge 1 ] || usage_exit; NTH=$1 ;;
-n|--nth) shift; NTH=$1 ;;
--id=*) SEQID=${1#--id=} ;;
-i|--id) shift; [ $# -ge 1 ] || usage_exit; SEQID=$1 ;;
-i|--id) shift; SEQID=$1 ;;
--grep=*) REGEX=${1#--grep=} ;;
-g|--grep) shift; [ $# -ge 1 ] || usage_exit; REGEX=$1 ;;
-g|--grep) shift; REGEX=$1 ;;
-h|--help) usage_exit 0 ;;
-) break ;;
*) usage_exit ;;
-) break ;;
*) usage_exit ;;
esac
shift
shift || usage_exit
done

# Handle option-less case
Expand Down
13 changes: 4 additions & 9 deletions uf-sort
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,11 @@ unset REVERSE

while [ $# -ne 0 -a "$(expr "$1" : '\(.\)..*')" = "-" ]; do
case $1 in
-r|--reverse)
REVERSE="-r"
;;
-h|--help)
usage_exit 0
;;
*) usage_exit
;;
-r|--reverse) REVERSE="-r" ;;
-h|--help) usage_exit 0 ;;
*) usage_exit ;;
esac
shift
shift || usage_exit
done

# Do the work
Expand Down
6 changes: 3 additions & 3 deletions uf-stats
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ BARE=0
while [ $# -ne 0 -a "$(expr "$1" : '\(.\)..*')" = "-" ]; do
case $1 in
--min-len*=*) MIN_LEN="${1##--min-len*=}" ;;
-m|--min-len) shift || usage_exit; MIN_LEN="$1" ;;
-m|--min-len) shift; MIN_LEN="$1" ;;
--delim=*) DELIM="${1##--delim=}" ;;
-d|--delim) shift || usage_exit; DELIM="$1" ;;
-d|--delim) shift; DELIM="$1" ;;
-t|--trans*) TRANS=1 ;;
-b|--bare) BARE=1 ;;
-h|--help) usage_exit 0 ;;
*) usage_exit ;;
esac
shift
shift || usage_exit
done

gawk -bO -v P="$(basename "$0")" -v MIN_LEN="$MIN_LEN" -v DELIM="$DELIM" -v TRANS="$TRANS" -v BARE="$BARE" '
Expand Down
Loading

0 comments on commit ea69d23

Please sign in to comment.