-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
92 lines (71 loc) · 1.83 KB
/
main.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"bytes"
"flag"
"fmt"
"github.com/satori/go.uuid"
"io"
"os"
"regexp"
"syscall"
)
var (
run_server bool
run_cli bool
)
var UUID_REGEXP = regexp.MustCompile("[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}")
type filename = string
func main() {
parse_flags()
if run_server {
serve()
} else if run_cli {
cli()
} else {
panic("What am I supposed to do? I am just a program.")
}
}
func parse_flags() {
flag.BoolVar(&run_server, "server", false, "Should I server")
flag.BoolVar(&run_cli, "cli", false, "Should I CLI")
// CLI flags
//
flag.StringVar(&command, "c", "", "Subcommand")
flag.StringVar(&inputfile, "i", "", "File to be processed")
flag.StringVar(&targetfile, "t", "", "Target file to use as reference for clipping/cropping")
flag.StringVar(&referencefile, "r", "", "File to be used as reference")
flag.StringVar(&idfield, "g", "OBJECTID", "blah blah")
flag.Var(&selectfields, "s", "Fields to extract from the features")
// SERVER flags
//
flag.Var(&roles, "role", "Roles permitted in the JWT claims")
flag.StringVar(&pubkeyfile, "pubkey", "", "Public key file to check JWTs")
flag.StringVar(&socket, "socket", "/tmp/paver-server.sock", "Socket file to run on")
flag.Parse()
}
func _filename() filename {
return tmpdir + "/" + uuid.NewV4().String()
}
func _uuid(s string) string {
return fmt.Sprintf("%s", UUID_REGEXP.Find([]byte(s)))
}
func trash(files ...filename) {
for _, f := range files {
if err := os.Remove(f); err != nil {
fmt.Println(err)
}
}
}
func capture() func() string {
r, w, _ := os.Pipe()
ostderr, _ := syscall.Dup(syscall.Stderr)
syscall.Dup2(int(w.Fd()), syscall.Stderr)
return func() string {
w.Close()
syscall.Close(syscall.Stderr)
var b bytes.Buffer
io.Copy(&b, r)
syscall.Dup2(ostderr, syscall.Stderr)
return b.String()
}
}