#!/usr/bin/env bash
# nerf-az-boards-wi-list -- Query work items using WIQL (Work Item Query Language). Returns matching work items as JSON. The organization and project are auto-detected from the git remote.
# Generated from az-boards manifest. Do not edit directly.
# nerf:threat:read=remote
# nerf:threat:write=none

set -euo pipefail

_NERF_DRY_RUN=""

usage() {
  cat >&2 <<'EOF'
Usage: nerf-az-boards-wi-list <wiql>

Arguments:
  <wiql> (required)
      WIQL query string (e.g. "SELECT [System.Id], [System.Title], [System.State] FROM WorkItems WHERE [System.AssignedTo] = @Me AND [System.State] <> 'Closed' ORDER BY [System.ChangedDate] DESC")

Maps to: az boards query --wiql <wiql> --output json

Query work items using WIQL (Work Item Query Language). Returns matching work items as JSON. The organization and project are auto-detected from the git remote..
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

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

if [[ -n "${WIQL}" ]] && [[ "${WIQL}" == -* ]]; then
  echo "error: nerf-az-boards-wi-list: <wiql> cannot start with '-'" >&2
  echo "  hint: use -- before positional arguments if needed" >&2
  exit 1
fi

if [[ -z "${WIQL}" ]]; then
  echo "error: nerf-az-boards-wi-list: missing required argument <wiql>" >&2
  echo "  hint: provide a value for <wiql>" >&2
  usage
fi

if [[ "$_NERF_DRY_RUN" == "true" ]]; then
  echo "dry-run: az boards query --wiql "${WIQL}" --output json"
  exit 0
fi

exec az boards query --wiql "${WIQL}" --output json
