mirror of
https://github.com/mappu/miqt.git
synced 2024-12-22 00:48:38 +00:00
uic: add main flag handling, add go:generate comment with preserved flags
This commit is contained in:
parent
6198406bfb
commit
5a2c8b726f
@ -2,33 +2,48 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
in, err := ioutil.ReadFile(`test.ui`)
|
||||
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)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var parsed UiFile
|
||||
err = xml.Unmarshal(in, &parsed)
|
||||
err = xml.Unmarshal(inXml, &parsed)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
ret, err := xml.MarshalIndent(parsed, "", " ")
|
||||
gosrc, err := generate(*packageName, strings.Join(os.Args[1:], " "), parsed)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(string(ret))
|
||||
if *outFile == "-" {
|
||||
fmt.Println(string(gosrc))
|
||||
|
||||
gosrc, err := generate("main", parsed)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
|
||||
err = ioutil.WriteFile(*outFile, gosrc, 0644)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println(string(gosrc))
|
||||
}
|
||||
|
@ -32,9 +32,14 @@ func collectClassNames(u UiFile) []string {
|
||||
return ret
|
||||
}
|
||||
|
||||
func generate(packageName string, u UiFile) ([]byte, error) {
|
||||
func generate(packageName string, goGenerateArgs string, u UiFile) ([]byte, error) {
|
||||
ret := strings.Builder{}
|
||||
ret.WriteString(`package ` + packageName + `
|
||||
ret.WriteString(`// Generated by miqt-uic. To update this file, edit the .ui file in
|
||||
// Qt Designer, and then run 'go generate'.
|
||||
//
|
||||
//go:` + `generate miqt-uic ` + goGenerateArgs + `
|
||||
|
||||
package ` + packageName + `
|
||||
|
||||
import (
|
||||
"github.com/mappu/miqt"
|
||||
|
Loading…
Reference in New Issue
Block a user