basic generation
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
commit
8402d724a9
4 changed files with 52 additions and 0 deletions
12
Makefile
Normal file
12
Makefile
Normal 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
5
g.go
Normal 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
30
gen.go
Normal 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
5
run.go
Normal file
|
@ -0,0 +1,5 @@
|
|||
package main
|
||||
|
||||
func main() {
|
||||
foo()
|
||||
}
|
Loading…
Reference in a new issue