#!/usr/bin/env bash
# nerf-tg-init -- Run terragrunt init in the current module directory.
# Generated from tg manifest. Do not edit directly.
# nerf:threat:read=remote
# nerf:threat:write=workspace

if [[ "${BASH_VERSINFO[0]:-0}" -lt 4 ]]; then
  echo "error: nerf-tg-init requires bash 4+. Found bash ${BASH_VERSION:-unknown}" >&2
  echo "  hint: on macOS, install a newer bash via 'brew install bash'" >&2
  exit 1
fi

set -euo pipefail

_NERF_DRY_RUN=""

usage() {
  cat >&2 <<'EOF'
Usage: nerf-tg-init [-upgrade]

Switches:
  -upgrade
      Upgrade modules and plugins to latest versions

Maps to: terragrunt init --non-interactive -input=false <upgrade>

Run terragrunt init in the current module directory.
EOF
  exit 1
}

UPGRADE=""

while [[ $# -gt 0 ]]; do
  case "$1" in
    -upgrade) if [[ -n "${UPGRADE}" ]]; then echo "error: -upgrade can only be specified once" >&2; exit 1; fi; UPGRADE="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
  _NERF_DRY_CMD=(terragrunt init --non-interactive -input=false ${UPGRADE:+"-upgrade"})
  printf 'dry-run:'
  for _a in "${_NERF_DRY_CMD[@]}"; do printf " %q" "$_a"; done
  echo
  exit 0
fi

exec terragrunt init --non-interactive -input=false ${UPGRADE:+"-upgrade"}
