From 809b25b1ac5a9e7b236b207d8d0e04579c2b055e Mon Sep 17 00:00:00 2001 From: Bill Rossi Date: Fri, 27 Dec 2024 12:35:07 -0500 Subject: [PATCH] Use more idiomatic clargs --- bin/run | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/bin/run b/bin/run index 4c45a47..105e4a9 100755 --- a/bin/run +++ b/bin/run @@ -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"