helper-scripts/getweather.sh
2018-12-15 21:24:42 -08:00

39 lines
730 B
Bash
Executable File

#!/usr/bin/bash
# Obtain a weather forecast
printHelp() {
cat << EOF
Retrieve the weather of a give location
Usage: getweather [-h|--help] [location]
Options:
-h show this help page
EOF
}
while true; do
case "${1}" in
"-h"|"--help")
printHelp
exit
;;
--)
shift
break
;;
-*)
echo "Not an option: ${1}" >&2 && exit 1
exit
;;
*)
break;
;;
esac
done
[[ ! -x '/usr/bin/curl' ]] && echo 'curl is required for this script' && exit 1
[[ -z "${@}" ]] && echo "Please enter a location" >&2 && exit 1
xargs --no-run-if-empty -I {} curl wttr.in/{} <<< "${@}"