#!/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

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="${1:-}"
shift 2>/dev/null || true

if [[ -n "${PROJECT}" ]] && [[ "${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}" ]] && ! [[ "${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
  echo "dry-run: npx nx show project "${PROJECT}""
  exit 0
fi

exec npx nx show project "${PROJECT}"
