forked from constabulary/gb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.go
42 lines (34 loc) · 998 Bytes
/
generate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"github.com/constabulary/gb"
"github.com/constabulary/gb/cmd"
)
func init() {
registerCommand(GenerateCmd)
}
var GenerateCmd = &cmd.Command{
Name: "generate",
UsageLine: "generate [-run regexp] [file.go... | packages]",
Short: "generate Go files by processing source",
Long: `
Generate runs commands described by directives within existing files.
Those commands can run any process, but the intent is to create or update Go
source files, for instance by running yacc.
See 'go help generate'.
`,
Run: func(ctx *gb.Context, args []string) error {
env := cmd.MergeEnv(os.Environ(), map[string]string{
"GOPATH": fmt.Sprintf("%s%c%s", ctx.Projectdir(), filepath.ListSeparator, filepath.Join(ctx.Projectdir(), "vendor")),
})
cmd := exec.Command("go", append([]string{"generate"}, args...)...)
cmd.Env = env
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
},
}