1#!/bin/bash -eu 2 3LIBDIR="$(dirname "$(readlink -f "$0")")" 4 5function print_usage() { 6 echo "Usage: query.sh [-C] <command> <graph JSON> [argument]" 1>&2 7 echo " -C: colorized output" 1>&2 8 echo 9 echo "Commands": 10 for jq in "$LIBDIR"/*.jq; do 11 if ! grep -q "^# CMD:" "$jq"; then 12 continue 13 fi 14 15 local CMD="$(echo $(basename "$jq") | sed 's/\..*$//')" 16 echo " $CMD": $(cat "$jq" | grep "^# CMD:" | head -n 1 | sed 's/^# CMD://') 17 done 18 exit 1 19} 20 21JQARGS="" 22 23while getopts "C" arg; do 24 case "$arg" in 25 C) 26 JQARGS="$JQARGS -C" 27 shift 28 ;; 29 *) 30 print_usage 31 ;; 32 esac 33done 34 35if [[ "$#" -lt 2 ]]; then 36 print_usage 37fi 38 39COMMAND="$1" 40GRAPH="$2" 41 42if [[ "$#" -gt 2 ]]; then 43 ARG="$3" 44else 45 ARG="" 46fi 47 48if [[ "$#" -gt 3 ]]; then 49 ARG2="$4" 50else 51 ARG2="" 52fi 53 54jq $JQARGS -L "$LIBDIR" -f "$LIBDIR/$COMMAND".jq "$GRAPH" --arg arg "$ARG" --arg arg2 "$ARG2" 55