2024-09-20 06:39:01 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/xml"
|
2024-09-20 06:51:47 +00:00
|
|
|
"flag"
|
2024-09-20 06:39:01 +00:00
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
2024-09-20 06:51:47 +00:00
|
|
|
"os"
|
|
|
|
"strings"
|
2024-09-20 06:39:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2024-09-20 06:51:47 +00:00
|
|
|
inFile := flag.String("InFile", "", "Input .ui file")
|
|
|
|
outFile := flag.String("OutFile", "-", "Output .go file, or - for stdout")
|
|
|
|
packageName := flag.String("Package", "main", "Custom package name")
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
if *inFile == "" {
|
|
|
|
flag.Usage()
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
inXml, err := ioutil.ReadFile(*inFile)
|
2024-09-20 06:39:01 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var parsed UiFile
|
2024-09-20 06:51:47 +00:00
|
|
|
err = xml.Unmarshal(inXml, &parsed)
|
2024-09-20 06:39:01 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2024-09-20 06:51:47 +00:00
|
|
|
gosrc, err := generate(*packageName, strings.Join(os.Args[1:], " "), parsed)
|
2024-09-20 06:39:01 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2024-09-20 06:51:47 +00:00
|
|
|
if *outFile == "-" {
|
|
|
|
fmt.Println(string(gosrc))
|
2024-09-20 06:39:01 +00:00
|
|
|
|
2024-09-20 06:51:47 +00:00
|
|
|
} else {
|
2024-09-20 06:39:01 +00:00
|
|
|
|
2024-09-20 06:51:47 +00:00
|
|
|
err = ioutil.WriteFile(*outFile, gosrc, 0644)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
2024-09-20 06:39:01 +00:00
|
|
|
}
|