miqt/cmd/miqt-uic/main.go

50 lines
797 B
Go
Raw Normal View History

2024-09-20 06:39:01 +00:00
package main
import (
"encoding/xml"
"flag"
2024-09-20 06:39:01 +00:00
"fmt"
"io/ioutil"
"os"
"strings"
2024-09-20 06:39:01 +00:00
)
func main() {
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
err = xml.Unmarshal(inXml, &parsed)
2024-09-20 06:39:01 +00:00
if err != nil {
panic(err)
}
gosrc, err := generate(*packageName, strings.Join(os.Args[1:], " "), parsed)
2024-09-20 06:39:01 +00:00
if err != nil {
panic(err)
}
if *outFile == "-" {
fmt.Println(string(gosrc))
2024-09-20 06:39:01 +00:00
} else {
2024-09-20 06:39:01 +00:00
err = ioutil.WriteFile(*outFile, gosrc, 0644)
if err != nil {
panic(err)
}
}
2024-09-20 06:39:01 +00:00
}