#!/usr/bin/env bash
# nerf-nx-show-project -- Show configuration details for a specific Nx project (targets, source root, metadata).
# Generated from nx manifest. Do not edit directly.
# nerf:threat:read=workspace
# nerf:threat:write=none

if [[ "${BASH_VERSINFO[0]:-0}" -lt 4 ]]; then
  echo "error: nerf-nx-show-project 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-nx-show-project <project>

Arguments:
  <project> (required)
      Nx project name (from nx-show-projects)
      Must match: ^[a-zA-Z0-9_-]+$

Maps to: npx nx show project <project>

Show configuration details for a specific Nx project (targets, source root, metadata).
EOF
  exit 1
}

while [[ $# -gt 0 ]]; do
  case "$1" in
    --nerf-dry-run) _NERF_DRY_RUN="true"; shift 1 ;;
    -h|--help) usage ;;
    --) shift; break ;;
    *) break ;;
  esac
done

_PROJECT_SET=""
if [[ $# -gt 0 ]]; then
  PROJECT="$1"
  _PROJECT_SET=true
  shift
else
  PROJECT=""
fi
if [[ $# -gt 0 ]]; then
  echo "error: nerf-nx-show-project: unexpected extra arguments: $*" >&2
  echo "  hint: switches and options must come before positional arguments" >&2
  exit 1
fi

if [[ -n "${_PROJECT_SET}" ]] && [[ "${PROJECT}" == -* ]]; then
  echo "error: nerf-nx-show-project: <project> cannot start with '-'" >&2
  echo "  hint: use -- before positional arguments if needed" >&2
  exit 1
fi

if [[ -z "${PROJECT}" ]]; then
  echo "error: nerf-nx-show-project: missing required argument <project>" >&2
  echo "  hint: provide a value for <project>" >&2
  usage
fi

_NERF_PATTERN='^[a-zA-Z0-9_-]+$'
if [[ -n "${_PROJECT_SET}" ]] && ! [[ "${PROJECT}" =~ $_NERF_PATTERN ]]; then
  echo "error: nerf-nx-show-project: argument <project> does not match required pattern" >&2
  echo "  value:   \"${PROJECT}\"" >&2
  echo "  pattern: ^[a-zA-Z0-9_-]+$" >&2
  echo "  hint: value must match ^[a-zA-Z0-9_-]+$" >&2
  exit 1
fi

test -f nx.json > /dev/null 2>&1 || { echo 'error: nerf-nx-show-project: Not in an Nx workspace root (nx.json not found). Run from the repo root.' >&2; exit 1; }

if [[ "$_NERF_DRY_RUN" == "true" ]]; then
  _NERF_DRY_CMD=(npx nx show project "${PROJECT}")
  printf 'dry-run:'
  for _a in "${_NERF_DRY_CMD[@]}"; do printf " %q" "$_a"; done
  echo
  exit 0
fi

exec npx nx show project "${PROJECT}"
