#! /bin/bash
#
# Generate a diff output based on the output of a command
# instead of the content of files.
# 
# Usage:   diff-cmd left right "command including IN"
# Examples:
#     diff-cmd https://somesite/stats.json https://othersite/stats.json "curl IN | jq -r --sort-keys"
#     diff-cmd configfile.ini config.example.ini "grep -v '^#' IN | sort"

test $# -lt 3 && exit 1

LEFT=$1
RIGHT=$2
CMD=$3
shift 3

CMD1=${CMD//IN/$LEFT}
CMD2=${CMD//IN/$RIGHT}

diff $@ --label "$LEFT" --label "$RIGHT" -u <(eval "$CMD1") <(eval "$CMD2")
