-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
61 lines (54 loc) · 1.51 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
package main
import (
"flag"
"fmt"
"os"
)
func main() {
helpMsg := flag.Bool("h", false, "show usage message")
targetLang := flag.String("l", "nil", "set a target language")
schemaFile := flag.String("s", "schema.json", "path to file containing JSON schema")
outputFile := flag.String("o", "output.txt", "path to output file")
publicDef := flag.Bool("p", false, "set values to public in output code")
flag.Parse()
if flag.NFlag() == 0 || *helpMsg {
usage()
os.Exit(1)
}
schema, err := readJSONSchema(*schemaFile)
if err != nil {
fmt.Println("Error:", err)
os.Exit(1)
}
if !checkPublicSupport(*targetLang) && *publicDef {
fmt.Println("Public is not supported for " + *targetLang)
fmt.Println("Choosing default settings")
}
switch *targetLang {
case "nil":
fmt.Println("No language specified")
os.Exit(1)
case "rust":
code := generateRustCode(schema, *publicDef)
writeCodeToFile(*outputFile, code)
case "c":
code := generateCCode(schema)
var outputCode string = cHeaderFormat() + code
writeCodeToFile(*outputFile, outputCode)
case "cpp":
code := generateCPPCode(schema)
var outputCode string = getCPPHeaderIncludes() + "\n\n" + code
writeCodeToFile(*outputFile, outputCode)
case "go":
code := generateGoCode(schema)
writeCodeToFile(*outputFile, code)
case "ts":
code := generateTSCode(schema)
writeCodeToFile(*outputFile, code)
case "java":
code := generateJavaCode(schema)
writeCodeToFile(*outputFile, code)
default:
fmt.Println(*targetLang + " is not supported :(")
}
}