diff options
| -rwxr-xr-x | new_game | 15 | ||||
| -rwxr-xr-x | send_game | 48 |
2 files changed, 58 insertions, 5 deletions
diff --git a/new_game b/new_game new file mode 100755 index 0000000..cf0fd5b --- /dev/null +++ b/new_game @@ -0,0 +1,15 @@ +#!/bin/bash + +base_url="https://jpappel.xyz/toggle" +[ "$1" == "localhost" ] && + base_url="localhost:9090/toggle" + +size="$2" +[ -z "$size" ] && + size="7" + +endpoint="game/new?size=$size" + +url="${base_url}/${endpoint}" + +curl -s "$url" | jq . @@ -1,11 +1,49 @@ #!/bin/bash -endpoint="/query" -URL="https://jpappel.xyz/toggle$endpoint" -[ "$2" == "localhost" ] && - URL="localhost:9090$endpoint" +args=`getopt h:o:i: $*` +if [ $? -ne 0 ]; then + echo 'Usage: send_game [-h HOST] [-o outfile] [-i infile]' + exit 2 +fi -jq . "$1" | curl -s "$URL" \ +set -- $args + +base_url="https://jpappel.xyz/toggle" +infile="-" +outfile="/dev/fd/0" + +while :; do + case "$1" in + -h) + base_url="$2" + [ "$base_url" == "localhost" ] && + base_url="localhost:9090/toggle" + shift; shift + ;; + -o) + outfile="$2" + [ "$outfile" == "-" ] && + outfile="/dev/fd/1" + shift; shift + ;; + -i) + infile="$2" + [ "$infile" == "-" ] && + infile="/dev/fd/0" + shift; shift + ;; + --) + shift + break + ;; + esac +done + +endpoint="game/play" + +url="${base_url}/${endpoint}" + +jq . "$infile" | curl -s "$url" \ --header "Content-Type: application/json" \ --request POST \ -d @- | |
