-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
66 lines (52 loc) · 1.22 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
// This program runs a command line program that generates Go code from an xgb model in JSON format.
package main
import (
"flag"
"fmt"
"log"
"os"
"github.com/maxmind/xgb2code/gen"
)
type language string
const languageGo language = "go"
func main() {
inputJSON := flag.String("input-json", "", "Path to the model as JSON")
lang := flag.String(
"language",
string(languageGo),
"Language to generate code for. Currently 'go' is supported.",
)
packageName := flag.String(
"go-package-name",
"",
"The package name to use when generating Go code. Must be a valid Go package name.",
)
funcName := flag.String(
"function-name",
"",
"The function name to use. Must be a valid Go function name.",
)
versionFlag := flag.Bool(
"version",
false,
"Print version and exit.",
)
outputFile := flag.String("output-file", "", "The file to write to")
flag.Parse()
if *versionFlag {
fmt.Printf("xgb2code v%s\n", version)
os.Exit(0)
}
if *inputJSON == "" ||
language(*lang) != languageGo ||
*packageName == "" ||
*funcName == "" ||
*outputFile == "" {
flag.Usage()
os.Exit(1)
}
err := gen.GenerateFile(*inputJSON, *packageName, *funcName, *outputFile)
if err != nil {
log.Fatal(err)
}
}