-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
82 lines (73 loc) · 1.62 KB
/
main.go
File metadata and controls
82 lines (73 loc) · 1.62 KB
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
package main
import (
"flag"
"fmt"
"io"
"os"
"strings"
htmlelements "github.com/gost-dom/code-gen/html-elements"
wrappers "github.com/gost-dom/code-gen/script-wrappers"
)
func getWriter(output string) io.Writer {
if output == "stdout" {
return os.Stdout
}
file, err := os.Create(output)
if err != nil {
fmt.Println("Error creating output file")
os.Exit(1)
}
return file
}
var generators = map[string]func(io.Writer) error{
"html-elements": generateHtmlElements,
}
func main() {
debug := flag.Bool("d", false, "Debug")
outputFile := flag.String("o", "", "Output file to write")
generatorType := flag.String("g", "", "Generator type")
flag.Parse()
switch *generatorType {
case "goja":
gen := wrappers.NewGojaWrapperModuleGenerator()
exitOnError(gen.GenerateScriptWrappers())
os.Exit(0)
return
case "scripting":
gen := wrappers.NewScriptWrapperModulesGenerator()
exitOnError(gen.GenerateScriptWrappers())
os.Exit(0)
return
case "htmlelements":
exitOnError(htmlelements.GenerateHTMLElements())
os.Exit(0)
return
case "dom":
exitOnError(htmlelements.GenerateDOMTypes())
os.Exit(0)
return
}
if *outputFile == "" || *generatorType == "" {
fmt.Println("Internal code generator from IDL definitions")
flag.PrintDefaults()
os.Exit(1)
}
if *debug {
fmt.Println(strings.Join(os.Args, " "))
fmt.Println("--------")
}
file := getWriter(*outputFile)
generator, ok := generators[*generatorType]
if !ok {
os.Exit(1)
}
err := generator(file)
exitOnError(err)
}
func exitOnError(err error) {
if err != nil {
fmt.Println("Error running generator")
fmt.Println(err)
os.Exit(1)
}
}