#!/usr/bin/env bash # # tooldance — a thin CLI over the tooldance HTTP service. # # Latest version and docs: https://tool.dance # - CLI: https://tool.dance/tooldance.sh # - Caller: https://tool.dance/caller.AGENTS.md # # tooldance show the readme (available tools) # tooldance echo '{"my":"json"}' call a tool with a raw JSON body # tooldance greet --name world call a tool with named params -> JSON # # Configure with: # TOOLDANCE_HOST base URL (optional, default https://tool.dance) # TOOLDANCE_KEY bearer token (required) # set -euo pipefail die() { echo "tooldance: $*" >&2; exit 1; } [[ -n "${TOOLDANCE_KEY:-}" ]] || die "TOOLDANCE_KEY is not set (your bearer token)" host="${TOOLDANCE_HOST:-https://tool.dance}" host="${host%/}" auth=(-H "Authorization: Bearer ${TOOLDANCE_KEY}") # Build a JSON object from --key value / --key=value / --flag arguments. params_to_json() { command -v jq >/dev/null 2>&1 \ || die "named params need 'jq' on PATH — or pass a raw JSON body instead" local out='{}' key val while [[ $# -gt 0 ]]; do key="$1"; shift [[ "$key" == --?* ]] || die "expected --flag, got: $key" key="${key#--}" if [[ "$key" == *=* ]]; then val="${key#*=}"; key="${key%%=*}" elif [[ $# -gt 0 && "$1" != --* ]]; then val="$1"; shift else val="true" # bare --flag fi if printf '%s' "$val" | jq . >/dev/null 2>&1; then out=$(jq --arg k "$key" --argjson v "$val" '. + {($k): $v}' <<<"$out") else out=$(jq --arg k "$key" --arg v "$val" '. + {($k): $v}' <<<"$out") fi done printf '%s' "$out" } # No tool -> show the readme, rendered in CLI flavor by the server. if [[ $# -eq 0 ]]; then curl -fsS "${auth[@]}" "$host/readme?format=cli" || die "failed to fetch readme from $host" echo exit 0 fi tool="$1"; shift if [[ $# -eq 0 ]]; then body='{}' elif [[ $# -eq 1 && "$1" != --* ]]; then body="$1" # raw JSON body else body="$(params_to_json "$@")" # named params -> JSON fi curl -fsS -X POST "${auth[@]}" \ -H "Content-Type: application/json" \ -d "$body" \ "$host/$tool" echo