-
Notifications
You must be signed in to change notification settings - Fork 26
/
cli.go
78 lines (72 loc) · 1.53 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
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
78
package main
import (
"fmt"
"log"
"os"
"strings"
"github.com/buckhx/gofence/geofence"
"github.com/codegangsta/cli"
)
var version string
func client(args []string) {
app := cli.NewApp()
app.Name = "fence"
app.Usage = "Fence geojson point features"
app.ArgsUsage = "path/to/geojson/dir"
app.Version = version // set with go tool link -X
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "fence",
Value: "rtree",
Usage: "Type of fence to use " + strings.Join(geofence.FenceLabels, "|"),
},
cli.IntFlag{
Name: "zoom, z",
Value: 14,
Usage: "Some fences require a zoom level",
},
cli.StringFlag{
Name: "port, p",
Value: "8080",
Usage: "Port to bind to",
},
cli.BoolFlag{
Name: "profile",
Usage: "Mount profiling endpoints",
},
}
app.Action = func(c *cli.Context) {
args := c.Args()
if len(args) < 1 || args[0] == "" {
die(c, "fences_path required")
}
z := c.Int("zoom")
if z < 0 || z > 23 {
die(c, "required 0 <= -z <= 23")
}
log.Println("Engarde!")
path := args[0]
label := c.String("fence")
fences, err := geofence.LoadFenceIndex(path, label, z)
if err != nil {
die(c, err.Error())
}
prof := c.Bool("profile")
if prof {
log.Println("Profiling available at /debug/pprof/")
}
port := fmt.Sprintf(":%s", c.String("port"))
err = geofence.ListenAndServe(port, fences, prof)
die(c, err.Error())
}
app.Run(args)
}
func main() {
client(os.Args)
}
func die(c *cli.Context, msg string) {
cli.ShowAppHelp(c)
fmt.Println("Touché!")
fmt.Println(msg)
os.Exit(1)
}