#!/usr/bin/env bash
# nerf-tg-fmt-all -- Run terragrunt HCL format across all units under the current directory
# Generated from tg manifest. Do not edit directly.
# nerf:threat:read=workspace
# nerf:threat:write=none

set -euo pipefail

_NERF_DRY_RUN=""

usage() {
  cat >&2 <<'EOF'
Usage: nerf-tg-fmt-all [--check]

Switches:
  --check
      Check formatting without modifying files (exits non-zero if files are unformatted)

Maps to: terragrunt run --all hcl format --non-interactive <check>

Run terragrunt HCL format across all units under the current directory.
EOF
  exit 1
}

CHECK=""

while [[ $# -gt 0 ]]; do
  case "$1" in
    --check) if [[ -n "${CHECK}" ]]; then echo "error: --check can only be specified once" >&2; exit 1; fi; CHECK="true"; shift 1 ;;
    --nerf-dry-run) _NERF_DRY_RUN="true"; shift 1 ;;
    -h|--help) usage ;;
    --) shift; break ;;
    *) echo "error: unknown argument: $1" >&2; usage ;;
  esac
done

if [[ "$_NERF_DRY_RUN" == "true" ]]; then
  echo "dry-run: terragrunt run --all hcl format --non-interactive ${CHECK:+"--check"}"
  exit 0
fi

exec terragrunt run --all hcl format --non-interactive ${CHECK:+"--check"}
