-
Notifications
You must be signed in to change notification settings - Fork 11
/
value.go
55 lines (48 loc) · 954 Bytes
/
value.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
46
47
48
49
50
51
52
53
54
55
package main
import (
"encoding/json"
"fmt"
"iconsole/tunnel"
"strings"
"github.com/urfave/cli"
)
func getAction(ctx *cli.Context) error {
udid := ctx.String("UDID")
args := ctx.Args()
if len(args) == 0 {
return nil
}
return session(udid, func(conn *tunnel.LockdownConnection) error {
for _, s := range args {
domain := ""
key := ""
a := strings.Split(s, ":")
if len(a) == 2 {
domain = a[0]
key = a[1]
} else if len(a) == 1 {
key = a[0]
} else {
return fmt.Errorf("Arguments too many `%s`", s)
}
if resp, err := conn.GetValue(domain, key); err != nil {
return err
} else {
if b, err := json.MarshalIndent(resp, "", "\t"); err != nil {
return err
} else {
fmt.Println(string(b))
}
}
}
return nil
})
}
func initValueCommond() cli.Command {
return cli.Command{
Name: "get",
Usage: "Get session value",
Action: getAction,
Flags: globalFlags,
}
}