afm-util: Fix report of error
[src/app-framework-main.git] / scripts / afm-util.in
1 #!/bin/bash
2
3 send() {
4         afb-client-demo -H -d unix:@afm_platform_rundir@/apis/ws/afm-main "$1" "$2" |
5         awk '$1=="ON-REPLY" && $3!="success"{$1="ERROR:";$2="";print > "/dev/stderr";exit 1;}NR>1'
6 }
7
8 case "$1" in
9
10   list|runnables)
11     send runnables true
12     ;;
13
14   add|install)
15     f=$(realpath $2)
16     r=true
17     if [[ "$(basename $0)" = "afm-install" ]]; then r=false; fi
18     send install '{"wgt":"'"$f"'","force":true,"reload":'"$r"'}'
19     ;;
20
21   remove|uninstall)
22     i=$2
23     send uninstall "\"$i\""
24     ;;
25
26   info|detail)
27     i=$2
28     send detail "\"$i\""
29     ;;
30
31   ps|runners)
32     send runners true
33     ;;
34
35   run|start)
36     i=$2
37     send start "\"$i\""
38     ;;
39
40   run-remote|start-remote)
41     i=$2
42     send start '{"id":"'"$i"'","mode":"remote"}'
43     ;;
44
45   once)
46     i=$2
47     send once "\"$i\""
48     ;;
49
50   terminate|kill)
51     i=$2
52     send terminate "$i"
53     ;;
54
55   stop|pause)
56     i=$2
57     send pause "$i"
58     ;;
59
60   resume|continue)
61     i=$2
62     send resume "$i"
63     ;;
64
65   state|status)
66     i=$2
67     send state "$i"
68     ;;
69
70   -h|--help|help)
71     cat << EOC
72 usage: $(basename $0) command [arg]
73
74 The commands are:
75
76   list
77   runnables      list the runnable widgets installed
78
79   add wgt
80   install wgt    install the wgt file
81
82   remove id
83   uninstall id   remove the installed widget of id
84
85   info id
86   detail id      print detail about the installed widget of id
87
88   ps
89   runners        list the running instance
90
91   run id
92   start id       start an instance of the widget of id
93
94   once id        run once an instance of the widget of id
95
96   kill rid
97   terminate rid  terminate the running instance rid
98
99   stop rid
100   pause rid      pause the running instance rid
101
102   resume rid
103   continue rid   continue the previously paused rid
104
105   status rid
106   state rid      get status of the running instance rid
107
108 EOC
109     ;;
110
111   *)
112     echo "unknown command $1" >&2
113     exit 1
114     ;;
115 esac
116
117