scripts: wm-request uses afb-client-demo
[staging/windowmanager.git] / scripts / wm-request
1 #!/bin/sh
2
3 nopygments=0
4 if [ "$1" = "-p" ]
5 then
6    nopygments=1
7    shift
8 fi
9
10 if ! [ "$1" ]
11 then
12    echo "Usage: $0 VERB [ARGS]" >&2
13    exit 1
14 fi
15
16 for i in uuidgen afb-client-demo
17 do
18    which $i 2>/dev/null 1>&2 || { echo "Program $i is missing" >&2; exit 1; }
19 done
20
21 set -eu
22
23 if which python 2>/dev/null 1>&2 && echo '{ "test": "1" }' | python -m json.tool 2>/dev/null 1>&2
24 then
25    if [ $nopygments = 0 ] && which pygmentize 2>/dev/null 1>&2
26    then
27       json_pretty() {
28          python -m json.tool | pygmentize -l json
29       }
30    else
31       json_pretty() {
32          python -m json.tool
33       }
34    fi
35 else
36    json_pretty() {
37       cat
38    }
39 fi
40
41 verb=$1
42 shift
43
44 UUIDFILE=/tmp/wm-request-uuid
45 if ! [ -f $UUIDFILE ]
46 then
47    uuidgen > $UUIDFILE
48 fi
49 UUID="`cat $UUIDFILE`"
50
51 args=
52 if [ "$1" ]
53 then
54    args='{"drawing_name":"'"$1"'"}'
55    shift
56 fi
57
58 afb-client-demo -H ws://localhost:1700/api\?token=wm\&uuid=$UUID winman $verb $args
59
60 # vim:set ft=sh: