-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.go
45 lines (40 loc) · 1.06 KB
/
cli.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"flag"
"fmt"
"net/rpc"
)
func cli(bindAddress string, id string) {
theme := flag.String("theme", "", "Set the current theme")
toaster := flag.String("toaster", "", "Pop a toaster")
download := flag.String("download", "", "Download a file")
flag.Parse()
rpcClient, err := rpc.DialHTTP("tcp", bindAddress)
if err != nil {
panic(err)
}
if *theme != "" {
var reply string
if err := rpcClient.Call("Context.SetTheme", &SetThemeArgs{RPCArgs: RPCArgs{ConnectionId: id}, ThemeId: *theme}, &reply); err != nil {
panic(err)
}
fmt.Println(reply)
}
if *toaster != "" {
var reply bool
if err := rpcClient.Call("Context.PopToaster", &PopToasterArgs{RPCArgs: RPCArgs{ConnectionId: id}, Text: *toaster}, &reply); err != nil {
panic(err)
}
if reply {
fmt.Println("Popped a toaster")
}
}
if *download != "" {
var reply string
if err := rpcClient.Call("Context.Download", &DownloadArgs{RPCArgs: RPCArgs{ConnectionId: id}, Path: *download}, &reply); err != nil {
panic(err)
}
fmt.Println(reply)
}
rpcClient.Close()
}