Use more idiomatic clargs

This commit is contained in:
Bill Rossi 2024-12-27 12:35:07 -05:00
parent c619806f7b
commit 809b25b1ac

41
bin/run
View File

@ -1,21 +1,45 @@
#!/usr/bin/env bash
show_help() {
echo "usage: $0 --lang=lang --year=year --day=day"
}
language=''
year='0'
day='0'
#
# check args
#
while :; do
case $1 in
-h|-\?|--help)
show_help # Display a usage synopsis.
exit
;;
--lang=?*)
language=${1#*=}
;;
--year=?*)
year=${1#*=}
;;
--day=?*)
day=${1#*=}
;;
-?*)
printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
;;
*)
break
esac
if [[ $# -ne 3 ]]
then
echo "usage: $0 year day"
exit 1
fi
shift
done
#
# check year and day
#
year=$(($2))
if [[ $year -lt 2015 ]]
then
echo "invalid year: $2"
@ -23,8 +47,6 @@ then
exit 2
fi
day=$(($3))
if [[ $day -lt 1 ]] || [[ $day -gt 25 ]]
then
echo "invalid day: $3"
@ -55,7 +77,6 @@ then
curl -s -b "$(cat ../cookie)" $input_url > $input_path
fi
language=$1
valid_languages=""
valid_language="false"