#!/usr/bin/env bash
# nerf-gh-pr-comment -- Add a comment to a pull request
# Generated from gh manifest. Do not edit directly.
# nerf:threat:read=remote
# nerf:threat:write=remote

set -euo pipefail

_NERF_DRY_RUN=""

usage() {
  cat >&2 <<'EOF'
Usage: nerf-gh-pr-comment <pr> <body>

Arguments:
  <pr> (required)
      PR number, URL, or branch name
  <body> (required)
      Comment text

Maps to: gh pr comment <pr> --body <body>

Add a comment to a pull request.
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

PR="${1:-}"
shift 2>/dev/null || true
BODY="${1:-}"
shift 2>/dev/null || true

if [[ -n "${PR}" ]] && [[ "${PR}" == -* ]]; then
  echo "error: nerf-gh-pr-comment: <pr> cannot start with '-'" >&2
  echo "  hint: use -- before positional arguments if needed" >&2
  exit 1
fi

if [[ -z "${PR}" ]]; then
  echo "error: nerf-gh-pr-comment: missing required argument <pr>" >&2
  echo "  hint: provide a value for <pr>" >&2
  usage
fi

if [[ -n "${BODY}" ]] && [[ "${BODY}" == -* ]]; then
  echo "error: nerf-gh-pr-comment: <body> cannot start with '-'" >&2
  echo "  hint: use -- before positional arguments if needed" >&2
  exit 1
fi

if [[ -z "${BODY}" ]]; then
  echo "error: nerf-gh-pr-comment: missing required argument <body>" >&2
  echo "  hint: provide a value for <body>" >&2
  usage
fi

if [[ "$_NERF_DRY_RUN" == "true" ]]; then
  echo "dry-run: gh pr comment "${PR}" --body "${BODY}""
  exit 0
fi

exec gh pr comment "${PR}" --body "${BODY}"
