-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathlaitos-cli.sh
executable file
·71 lines (61 loc) · 1.71 KB
/
laitos-cli.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env bash
# A WIP laitos cli shell script.
set -Eeuo pipefail
export LANG=C LC_ALL=C
handle_exit() {
local -r -i exit_status="$?"
echo "exiting with status code $exit_status"
exit $exit_status
}
trap handle_exit INT HUP TERM QUIT EXIT
print_usage() {
local -r -i exit_status="$1"
echo "$0 - laitos client CLI"
echo "-u, --url"
printf "\tInfo endpoint URLs (e.g. https://example.com/laitos-info), separated by comma, may be repeated.\n"
exit $exit_status
}
main() {
local -a url_argv=() urls=()
while true; do
local arg_val=''
if [ $# -eq 0 ]; then
break
fi
case "$1" in
-h | --help)
print_usage 0
;;
--url=*)
arg_val="${1#*=}"
;&
-u | --url)
if [ ! "$arg_val" ]; then
shift
[ $# -ge 1 ] && arg_val="$1"
fi
[ ! "$arg_val" ] && print_usage 1
url_argv+=("$arg_val")
;;
esac
shift
done
# Split possibly comma separated server arg values.
for argv in "${url_argv[@]}"; do
while IFS=',' read -r -a fields; do
urls+=("${fields[@]}")
done <<<"$argv"
done
printf "Fetching server info from %s URLs...\n" "${#urls[@]}"
local -A resp=()
for url in "${urls[@]}"; do
mapfile -d $'\0' resp_body < <(curl -H 'Accept: application/json' "$url" 2>/dev/null)
resp["$url"]="$resp_body"
wait
done
for key in "${!resp[@]}"; do
local val="${resp["$key"]}"
printf "%s response length %s\n" "$key" "${#val}"
done
}
main "${@}"