#!/usr/bin/env bash
# tool-info <name> — detail for a single tool (description, flags, example).
set -euo pipefail

JSON="${TOOLS_JSON:-/pentester/tools.json}"
if [ ! -f "$JSON" ]; then
  echo "tools.json not found at $JSON" >&2
  exit 1
fi

name="${1:-}"
if [ -z "$name" ]; then
  echo "usage: tool-info <name>" >&2
  exit 1
fi

match=$(jq -c --arg n "$name" '
  [.categories[] | .[] | select(.name == $n or .bin == $n)][0]
' "$JSON")

if [ "$match" = "null" ] || [ -z "$match" ]; then
  echo "unknown tool: $name" >&2
  exit 1
fi

echo "$match" | jq -r '"name:        " + .name,
                     "bin:         " + .bin,
                     "description: " + .description,
                     "common_flags: " + ((.common_flags // []) | join(" ")),
                     "examples:",
                     (.examples[] | "  " + .)'
