-
Notifications
You must be signed in to change notification settings - Fork 11
/
sim.go
77 lines (68 loc) · 1.58 KB
/
sim.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"iconsole/services"
"github.com/urfave/cli"
)
func startSimAction(ctx *cli.Context) error {
udid := ctx.String("UDID")
lon := ctx.Float64("lon")
lat := ctx.Float64("lat")
coor := ctx.String("coor")
device, err := getDevice(udid)
if err != nil {
return err
} else if sls, err := services.NewSimulateLocationService(device); err != nil {
return err
} else if err := sls.Start(lon, lat, coor); err != nil {
return err
}
return err
}
func stopSimAction(ctx *cli.Context) error {
udid := ctx.String("UDID")
device, err := getDevice(udid)
if err != nil {
return err
} else if sls, err := services.NewSimulateLocationService(device); err != nil {
return err
} else if err := sls.Stop(); err != nil {
return err
}
return err
}
func initSimCommond() cli.Command {
return cli.Command{
Name: "simlocation",
ShortName: "sim",
Usage: "A mounted developer disk image is required on the device.",
Subcommands: []cli.Command{
{
Name: "start",
Action: startSimAction,
Flags: append(globalFlags, cli.Float64Flag{
Name: "latitude, lat",
EnvVar: "LATITUDE",
Required: true,
Value: 0,
},
cli.Float64Flag{
Name: "longtitude, lon",
EnvVar: "LONGTITUDE",
Required: true,
Value: 0,
},
cli.StringFlag{
Name: "coordinate, coor",
EnvVar: "COORDINATE",
Usage: "coordinate name `gcj02` `wsg84` `bd09` default `gcj02`",
Value: "gcj02",
}),
},
{
Name: "stop",
Action: stopSimAction,
Flags: globalFlags,
},
},
}
}