Route the healthcheck output through one helper #16
@@ -1,14 +1,23 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# emit <format> <template> [args...]: the single output path.
|
||||
# format: text or json print; none suppresses (--quiet). Explicit argument,
|
||||
# never read from an enclosing variable.
|
||||
emit() {
|
||||
local format=$1
|
||||
shift
|
||||
[ "$format" = none ] || printf "$@"
|
||||
}
|
||||
|
||||
main() {
|
||||
local quiet=
|
||||
local json=
|
||||
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'
|
||||
emit text 'Usage: %s [--quiet]\n\n' "${0##*/}"
|
||||
emit text 'Healthcheck script for Orchestra E2E tests.\n'
|
||||
emit text 'Exits 0 with a success message if all checks pass.\n'
|
||||
emit text ' --quiet Suppress the success message; still exits 0.\n'
|
||||
exit 0
|
||||
elif [ "$arg" = --quiet ]; then
|
||||
quiet=1
|
||||
@@ -17,12 +26,16 @@ main() {
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -n "$json" ]; then
|
||||
printf '{"status":"ok","checks":1}\n'
|
||||
local format=text
|
||||
[ -n "$quiet" ] && format=none
|
||||
[ -n "$json" ] && format=json
|
||||
|
||||
if [ "$format" = json ]; then
|
||||
emit "$format" '{"status":"ok","checks":1}\n'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
[ -n "$quiet" ] || printf 'OK - all healthchecks passed\n'
|
||||
emit "$format" 'OK - all healthchecks passed\n'
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user