#!/bin/sh # getScryfallJSON.sh: Gets the JSON of a fuzzy Scryfall search. # # Usage: getScryfallJSON.sh CARDNAME usageMessage="Usage: ${0} FILE..." error() { printf '%s error: %s\n' "$0" "$*" >&2 } errorAndUsage() { printf '%s error: %s\n%s\n' "$0" "$*" "$usageMessage" >&2 } # Process options while getopts ':' opt; do case $opt in '?' ) printf '%s\n' "$usageMessage" >&2 exit 1 esac done shift $((OPTIND - 1)) url="$(echo "https://api.scryfall.com/cards/named?fuzzy=${*}" | sed 's/ /+/g')" json="$(curl "$url" 2>/dev/null)" if echo "$json" | jq -r .object | grep -q 'error'; then echo "Error: $(echo "$json" | jq)" >&2 exit 1 fi echo "$json"