build: Let "go generate" create assets

This commit is contained in:
Jakob Borg
2018-06-26 09:14:21 +02:00
parent 406b394704
commit ef5ca0c218
5 changed files with 28 additions and 6 deletions

View File

@@ -86,6 +86,7 @@ type templateVars struct {
}
func main() {
outfile := flag.String("o", "", "Name of output file (default stdout)")
flag.Parse()
filepath.Walk(flag.Arg(0), walkerFor(flag.Arg(0)))
@@ -104,7 +105,17 @@ func main() {
})
bs, err := format.Source(buf.Bytes())
if err != nil {
panic(err)
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
os.Stdout.Write(bs)
out := io.Writer(os.Stdout)
if *outfile != "" {
out, err = os.Create(*outfile)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
out.Write(bs)
}