From f80fb1e908c8a07aac2c6846246bce80657ee2a5 Mon Sep 17 00:00:00 2001 From: Asa Venton Date: Sun, 20 Oct 2019 12:57:59 +0100 Subject: Add check for empty imput, add response for no matching bus stops, fix exit codes and comments --- livetimes.sh | 8 ++++++-- 1 file 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 ' where 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 -- cgit v1.2.3