Script 'schedule': use built-in 'getopts' to parse arguments.

This commit is contained in:
vonavi 2014-04-20 14:42:19 +04:00
parent 1ebe482460
commit 19b85b5256

View File

@ -241,15 +241,16 @@ info_output_html() {
echo echo
} }
# Note that we use '"$@"' to let each command-line parameter expand to a checkargs() {
# separate word. The quotes around '$@' are essential! if [[ "$OPTARG" =~ ^-[apflhv]$ ]]; then
# We need 'opts' as the 'eval set --' would nuke the return value of getopt echo "Option -${opt}: argument not found"
opts=$(getopt --options ap:f:lh \ exit 1
--longoptions all,player:,format:,link,help \ fi
-- "$@") if [[ "$opt" == f && ! "$OPTARG" =~ ^(term|html|lor)$ ]]; then
echo "Incorrect FORMAT specified"
# Note the quotes around '$opts': they are essential! exit 1
eval set -- "$opts" fi
}
SHOW_ALL=false SHOW_ALL=false
PLAYER="" PLAYER=""
@ -257,28 +258,26 @@ FORMAT=term
SHOW_LINK=false SHOW_LINK=false
BASEURL="https://raw.github.com/${REPO}/master/${TOURNAMENT}" BASEURL="https://raw.github.com/${REPO}/master/${TOURNAMENT}"
while true; do while getopts "ap:f:lhv" opt; do
case "$1" in case "$opt" in
-a|--all) a) SHOW_ALL=true
SHOW_ALL=true ;;
shift;; p) checkargs
-p|--player) PLAYER="$OPTARG"
PLAYER="$2" ;;
shift 2;; f) checkargs
-f|--format) FORMAT="$OPTARG"
FORMAT="$2" ;;
shift 2;; l) SHOW_LINK=true
-l|--link) ;;
SHOW_LINK=true h) usage && exit 0
shift;; ;;
-h|--help) v) version && exit 0
usage ;;
break;;
--)
shift
show_tour_sequence "$@"
break;;
esac esac
done done
shift $(($OPTIND - 1))
show_tour_sequence "$@"
exit 0 exit 0