forked from twpayne/gogeom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.go
86 lines (76 loc) · 1.58 KB
/
generate.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
package main
import (
"flag"
"log"
"os"
"text/template"
)
type dim struct {
Z string
M string
ZM string
}
var dims = []dim{
{Z: "", M: "", ZM: ""},
{Z: "Z", M: "", ZM: "Z"},
{Z: "", M: "M", ZM: "M"},
{Z: "Z", M: "M", ZM: "ZM"},
}
var vars = struct {
Dims []dim
}{dims}
func generate(filename string) error {
t, err := template.ParseFiles(filename + ".tmpl")
if err != nil {
return err
}
w, err := os.Create(filename)
if err != nil {
return err
}
defer w.Close()
if err := t.Execute(w, vars); err != nil {
return err
}
return nil
}
func main() {
var clean = flag.Bool("clean", false, "")
flag.Parse()
var filenames = []string{
"geom/geom.go",
"geom/bounds.go",
"geom/point.go",
"geom/linestring.go",
"geom/polygon.go",
"geom/multipoint.go",
"geom/multilinestring.go",
"geom/multipolygon.go",
"geom/geometrycollection.go",
"geom/similar.go",
"geom/encoding/wkb/wkb.go",
"geom/encoding/wkb/point.go",
"geom/encoding/wkb/linestring.go",
"geom/encoding/wkb/polygon.go",
"geom/encoding/wkb/multipoint.go",
"geom/encoding/wkb/multilinestring.go",
"geom/encoding/wkb/multipolygon.go",
"geom/encoding/wkb/geometrycollection.go",
"geom/encoding/wkt/point.go",
"geom/encoding/wkt/linestring.go",
"geom/encoding/wkt/multilinestring.go",
"geom/encoding/wkt/polygon.go",
"geom/encoding/wkt/multipolygon.go",
}
if *clean {
for _, filename := range filenames {
os.Remove(filename)
}
} else {
for _, filename := range filenames {
if err := generate(filename); err != nil {
log.Fatalf("%s: %s", filename, err)
}
}
}
}