summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsa Venton <asav1410@gmail.com>2019-10-20 12:57:59 +0100
committerAsa Venton <asav1410@gmail.com>2019-10-20 12:57:59 +0100
commitf80fb1e908c8a07aac2c6846246bce80657ee2a5 (patch)
tree10390ede6a5583bf36d34b0b0bac5e2589d338ea
parent3bd3c5778a4f8ff674b20860bac5b3152579d555 (diff)
Add check for empty imput, add response for no matching bus stops, fix exit codes and comments
-rwxr-xr-xlivetimes.sh8
1 files changed, 6 insertions, 2 deletions
diff --git a/livetimes.sh b/livetimes.sh
index 6f0feb1..55d143f 100755
--- a/livetimes.sh
+++ b/livetimes.sh
@@ -17,7 +17,6 @@ _liveresult() {
result="$result Route: $(_jq '.service_number')\n"
done
echo -e $result
- # is this the correct exit code?
exit 0
}
@@ -28,6 +27,9 @@ _stopsreturn() {
if [ $stopslen = 1 ]; then
stop=$(echo ${stops} | jq '.[].stop_id')
_liveresult
+ elif [ $stopslen = 0 ]; then
+ echo "No results found."
+ exit 1
# multiple stops returned in $stops so we will return stop names and codes so user can retry
else
for json in $(echo "${stops}" | jq -r '.[] | @base64'); do
@@ -35,7 +37,6 @@ _stopsreturn() {
result="$result Code: $(_jq '.stop_id')\n"
done
echo -e $result
- # is this the correct exit code?
exit 0
fi
}
@@ -46,6 +47,9 @@ if [ "$stop" == "-h" ] || [ "$stop" == "--help" ]; then
exit 0
elif [[ "$stop" =~ ^-?[0-9]+$ ]] && [ $(echo ${#stop} == 4) ]; then
_liveresult
+elif [[ -z "${stop// }" ]]; then
+ echo "Input empty. Usage: '!livetimes <stop>' where <stop> is either the 4 digit stop code, the full unique or partial bus stop name. If a bus stop name is used and there are multiple matches then a list of matching stops will be returned with their codes."
+ exit 1
else
_stopsreturn
fi