37 lines
1.1 KiB
Bash
37 lines
1.1 KiB
Bash
#!/usr/bin/env bash
|
|
# Flag parsing for orchestra_e2e_healthcheck.sh. Sourced, not executed.
|
|
# parse_flags sets quiet, json and strict; it exits 0 on --help, and exits 1
|
|
# under --strict on the first unrecognised argument.
|
|
|
|
parse_flags() {
|
|
quiet=
|
|
json=
|
|
strict=
|
|
unset unknown
|
|
for arg in "$@"; do
|
|
if [ "$arg" = --help ]; then
|
|
printf 'Usage: %s [--quiet]\n\n' "${0##*/}"
|
|
printf 'Healthcheck script for Orchestra E2E tests.\n'
|
|
printf 'Exits 0 with a success message if all checks pass.\n'
|
|
printf ' --quiet Suppress the success message; still exits 0.\n'
|
|
exit 0
|
|
elif [ "$arg" = --quiet ]; then
|
|
quiet=1
|
|
elif [ "$arg" = --json ]; then
|
|
json=1
|
|
elif [ "$arg" = --strict ]; then
|
|
strict=1
|
|
else
|
|
# Keep the first unrecognised argument only. ${unknown+x} tests set-ness,
|
|
# so an empty-string argument is recorded too.
|
|
[ -n "${unknown+x}" ] || unknown=$arg
|
|
fi
|
|
done
|
|
|
|
# Deferred past the loop so --help still wins from any position.
|
|
if [ -n "$strict" ] && [ -n "${unknown+x}" ]; then
|
|
printf 'unknown flag: %s\n' "$unknown" >&2
|
|
exit 1
|
|
fi
|
|
}
|