basic generation

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2018-06-27 11:39:46 -04:00
commit 8402d724a9
Signed by: vbatts
GPG Key ID: 10937E57733F1362
4 changed files with 52 additions and 0 deletions

12
Makefile Normal file
View File

@ -0,0 +1,12 @@
run: farts
./farts
farts: $(wildcard *.go) farts.go
go build -o $@ .
farts.go:
go generate
clean:
rm -rf *~ farts.go farts

5
g.go Normal file
View File

@ -0,0 +1,5 @@
//go:generate go run gen.go -o farts.go
package main
// this file is _just_ here to snag the `go generate` command. Logic is in gen.go

30
gen.go Normal file
View File

@ -0,0 +1,30 @@
// +build ignore
package main
import (
"flag"
"io/ioutil"
"log"
"os"
)
var flOutput = flag.String("o", "", "output file to write")
func main() {
flag.Parse()
err := ioutil.WriteFile(*flOutput, []byte(source), os.FileMode(0644))
if err != nil {
log.Fatal(err)
}
}
var source = `
package main
import "fmt"
func foo() {
fmt.Println("brrnnt")
}
`

5
run.go Normal file
View File

@ -0,0 +1,5 @@
package main
func main() {
foo()
}