#!/usr/bin/env bash
# nerf-az-resource-show -- Show full details for a resource by ID.
# Generated from az-resource 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-resource-show [--subscription <subscription>] <resource_id>

Options:
  --subscription <subscription>
      Subscription name or ID (defaults to active)

Arguments:
  <resource_id> (required)
      Full resource ID (/subscriptions/.../resourceGroups/.../providers/...)

Maps to: az resource show --ids <resource_id> <subscription> --output json

Show full details for a resource by ID.
EOF
  exit 1
}

SUBSCRIPTION=""
_SUBSCRIPTION_SET=""

while [[ $# -gt 0 ]]; do
  case "$1" in
    --subscription) if [[ -n "${_SUBSCRIPTION_SET}" ]]; then echo "error: --subscription can only be specified once" >&2; exit 1; fi; SUBSCRIPTION="$2"; _SUBSCRIPTION_SET=true; shift 2 ;;
    --nerf-dry-run) _NERF_DRY_RUN="true"; shift 1 ;;
    -h|--help) usage ;;
    --) shift; break ;;
    *) break ;;
  esac
done

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

if [[ -n "${_RESOURCE_ID_SET}" ]] && [[ "${RESOURCE_ID}" == -* ]]; then
  echo "error: nerf-az-resource-show: <resource_id> cannot start with '-'" >&2
  echo "  hint: use -- before positional arguments if needed" >&2
  exit 1
fi

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

if [[ "$_NERF_DRY_RUN" == "true" ]]; then
  _NERF_DRY_CMD=(az resource show --ids "${RESOURCE_ID}" ${_SUBSCRIPTION_SET:+"--subscription"} ${_SUBSCRIPTION_SET:+"$SUBSCRIPTION"} --output json)
  printf 'dry-run:'
  for _a in "${_NERF_DRY_CMD[@]}"; do printf " %q" "$_a"; done
  echo
  exit 0
fi

exec az resource show --ids "${RESOURCE_ID}" ${_SUBSCRIPTION_SET:+"--subscription"} ${_SUBSCRIPTION_SET:+"$SUBSCRIPTION"} --output json
