addional args for go commands

This commit is contained in:
alessio 2017-09-03 20:00:40 +02:00
parent d484666747
commit 0bf537424c
5 changed files with 44 additions and 30 deletions

View File

@ -25,27 +25,27 @@ func (h *Blueprint) Run(p *cli.Context) error {
if p.String("name") != "" && h.Projects[k].Name != p.String("name") { if p.String("name") != "" && h.Projects[k].Name != p.String("name") {
continue continue
} }
if element.Cmds.Fmt { if element.Cmds.Fmt.Status {
h.Projects[k].tools.Fmt = tool{ h.Projects[k].tools.Fmt = tool{
status: &h.Projects[k].Cmds.Fmt, status: &h.Projects[k].Cmds.Fmt.Status,
cmd: "gofmt", cmd: "gofmt",
options: []string{"-s", "-w", "-e"}, options: arguments([]string{}, element.Cmds.Fmt.Args),
name: "Go Fmt", name: "Go Fmt",
} }
} }
if element.Cmds.Generate { if element.Cmds.Generate.Status {
h.Projects[k].tools.Generate = tool{ h.Projects[k].tools.Generate = tool{
status: &h.Projects[k].Cmds.Generate, status: &h.Projects[k].Cmds.Generate.Status,
cmd: "go", cmd: "go",
options: []string{"generate"}, options: arguments([]string{"generate"}, element.Cmds.Generate.Args),
name: "Go Generate", name: "Go Generate",
} }
} }
if element.Cmds.Test { if element.Cmds.Test.Status {
h.Projects[k].tools.Test = tool{ h.Projects[k].tools.Test = tool{
status: &h.Projects[k].Cmds.Test, status: &h.Projects[k].Cmds.Test.Status,
cmd: "go", cmd: "go",
options: []string{"test"}, options: arguments([]string{"test"}, element.Cmds.Test.Args),
name: "Go Test", name: "Go Test",
} }
} }
@ -58,6 +58,7 @@ func (h *Blueprint) Run(p *cli.Context) error {
} }
} }
h.Projects[k].parent = h h.Projects[k].parent = h
h.Projects[k].Settings = *h.Settings
h.Projects[k].path = h.Projects[k].Path h.Projects[k].path = h.Projects[k].Path
// env variables // env variables
@ -81,7 +82,7 @@ func (h *Blueprint) Run(p *cli.Context) error {
h.Projects[k].base = filepath.Join(wd, element.path) h.Projects[k].base = filepath.Join(wd, element.path)
} }
if h.Legacy.Status { if h.Legacy.Interval != 0 {
go h.Projects[k].watchByPolling() go h.Projects[k].watchByPolling()
} else { } else {
go h.Projects[k].watchByNotify() go h.Projects[k].watchByNotify()
@ -100,9 +101,15 @@ func (h *Blueprint) Add(p *cli.Context) error {
Path: h.Path(p.String("path")), Path: h.Path(p.String("path")),
Cmds: Cmds{ Cmds: Cmds{
Vet: p.Bool("vet"), Vet: p.Bool("vet"),
Fmt: !p.Bool("no-fmt"), Fmt: Cmd{
Test: p.Bool("test"), Status: !p.Bool("no-fmt"),
Generate: p.Bool("generate"), },
Test: Cmd{
Status: !p.Bool("test"),
},
Generate: Cmd{
Status: !p.Bool("generate"),
},
Build: Cmd{ Build: Cmd{
Status: p.Bool("build"), Status: p.Bool("build"),
}, },

View File

@ -114,10 +114,7 @@ func (p *Project) goBuild() (string, error) {
var out bytes.Buffer var out bytes.Buffer
var stderr bytes.Buffer var stderr bytes.Buffer
args := []string{"build"} args := []string{"build"}
for _, arg := range p.Cmds.Build.Args { args = arguments(args, p.Cmds.Build.Args)
arr := strings.Fields(arg)
args = append(args, arr...)
}
build := exec.Command("go", args...) build := exec.Command("go", args...)
build.Dir = p.base build.Dir = p.base
build.Stdout = &out build.Stdout = &out

View File

@ -61,9 +61,9 @@ type tool struct {
// Cmds go supported // Cmds go supported
type Cmds struct { type Cmds struct {
Vet bool `yaml:"vet,omitempty" json:"vet,omitempty"` Vet bool `yaml:"vet,omitempty" json:"vet,omitempty"`
Fmt bool `yaml:"fmt,omitempty" json:"fmt,omitempty"` Fmt Cmd `yaml:"fmt,omitempty" json:"fmt,omitempty"`
Test bool `yaml:"test,omitempty" json:"test,omitempty"` Test Cmd `yaml:"test,omitempty" json:"test,omitempty"`
Generate bool `yaml:"generate,omitempty" json:"generate,omitempty"` Generate Cmd `yaml:"generate,omitempty" json:"generate,omitempty"`
Bin Cmd `yaml:"bin" json:"bin"` Bin Cmd `yaml:"bin" json:"bin"`
Build Cmd `yaml:"build,omitempty" json:"build,omitempty"` Build Cmd `yaml:"build,omitempty" json:"build,omitempty"`
Run bool `yaml:"run,omitempty" json:"run,omitempty"` Run bool `yaml:"run,omitempty" json:"run,omitempty"`
@ -90,6 +90,7 @@ type Command struct {
Command string `yaml:"command" json:"command"` Command string `yaml:"command" json:"command"`
Path string `yaml:"path,omitempty" json:"path,omitempty"` Path string `yaml:"path,omitempty" json:"path,omitempty"`
Global bool `yaml:"global,omitempty" json:"global,omitempty"` Global bool `yaml:"global,omitempty" json:"global,omitempty"`
Output bool `yaml:"output,omitempty" json:"output,omitempty"`
} }
// Buffer define an array buffer for each log files // Buffer define an array buffer for each log files

View File

@ -9,6 +9,7 @@ import (
"github.com/tockins/realize/style" "github.com/tockins/realize/style"
cli "gopkg.in/urfave/cli.v2" cli "gopkg.in/urfave/cli.v2"
"strings"
) )
// Argsparam parse one by one the given argumentes // Argsparam parse one by one the given argumentes
@ -57,3 +58,12 @@ func getEnvPath(env string) string {
} }
return path[0] return path[0]
} }
// Split each arguments in multiple fields
func arguments(args, fields []string) []string {
for _, arg := range fields {
arr := strings.Fields(arg)
args = append(args, arr...)
}
return args
}

View File

@ -290,7 +290,7 @@ func (p *Project) cmd(flag string, global bool) {
} else { } else {
p.stamp("log", out, msg, "") p.stamp("log", out, msg, "")
} }
if logs != "" { if logs != "" && cmd.Output {
msg = fmt.Sprintln(logs) msg = fmt.Sprintln(logs)
out = BufferOut{Time: time.Now(), Text: logs, Type: flag} out = BufferOut{Time: time.Now(), Text: logs, Type: flag}
p.stamp("log", out, "", msg) p.stamp("log", out, "", msg)
@ -316,8 +316,8 @@ func (p *Project) ignore(str string) bool {
// Routines launches the toolchain run, build, install // Routines launches the toolchain run, build, install
func (p *Project) routines(wr *sync.WaitGroup, channel chan bool, watcher watcher, file string) { func (p *Project) routines(wr *sync.WaitGroup, channel chan bool, watcher watcher, file string) {
if len(file) > 0 {
p.cmd("before", false) p.cmd("before", false)
if len(file) > 0 {
path := filepath.Dir(file) path := filepath.Dir(file)
p.tool(file, p.tools.Fmt) p.tool(file, p.tools.Fmt)
p.tool(path, p.tools.Vet) p.tool(path, p.tools.Vet)
@ -336,7 +336,6 @@ func (p *Project) routines(wr *sync.WaitGroup, channel chan bool, watcher watche
if len(file) > 0 { if len(file) > 0 {
p.cmd("after", false) p.cmd("after", false)
} }
} }
// Defines the colors scheme for the project name // Defines the colors scheme for the project name
@ -366,8 +365,8 @@ func (p *Project) stamp(t string, o BufferOut, msg string, stream string) {
switch t { switch t {
case "out": case "out":
p.Buffer.StdOut = append(p.Buffer.StdOut, o) p.Buffer.StdOut = append(p.Buffer.StdOut, o)
if p.Resources.Outputs.Status { if p.Files.Outputs.Status {
f := p.Create(p.base, p.Resources.Outputs.Name) f := p.Create(p.base, p.Files.Outputs.Name)
t := time.Now() t := time.Now()
s := []string{t.Format("2006-01-02 15:04:05"), strings.ToUpper(p.Name), ":", o.Text, "\r\n"} s := []string{t.Format("2006-01-02 15:04:05"), strings.ToUpper(p.Name), ":", o.Text, "\r\n"}
if _, err := f.WriteString(strings.Join(s, " ")); err != nil { if _, err := f.WriteString(strings.Join(s, " ")); err != nil {
@ -376,8 +375,8 @@ func (p *Project) stamp(t string, o BufferOut, msg string, stream string) {
} }
case "log": case "log":
p.Buffer.StdLog = append(p.Buffer.StdLog, o) p.Buffer.StdLog = append(p.Buffer.StdLog, o)
if p.Resources.Logs.Status { if p.Files.Logs.Status {
f := p.Create(p.base, p.Resources.Logs.Name) f := p.Create(p.base, p.Files.Logs.Name)
t := time.Now() t := time.Now()
s := []string{t.Format("2006-01-02 15:04:05"), strings.ToUpper(p.Name), ":", o.Text, "\r\n"} s := []string{t.Format("2006-01-02 15:04:05"), strings.ToUpper(p.Name), ":", o.Text, "\r\n"}
if stream != "" { if stream != "" {
@ -389,8 +388,8 @@ func (p *Project) stamp(t string, o BufferOut, msg string, stream string) {
} }
case "error": case "error":
p.Buffer.StdErr = append(p.Buffer.StdErr, o) p.Buffer.StdErr = append(p.Buffer.StdErr, o)
if p.Resources.Errors.Status { if p.Files.Errors.Status {
f := p.Create(p.base, p.Resources.Errors.Name) f := p.Create(p.base, p.Files.Errors.Name)
t := time.Now() t := time.Now()
s := []string{t.Format("2006-01-02 15:04:05"), strings.ToUpper(p.Name), ":", o.Type, o.Text, o.Path, "\r\n"} s := []string{t.Format("2006-01-02 15:04:05"), strings.ToUpper(p.Name), ":", o.Type, o.Text, o.Path, "\r\n"}
if stream != "" { if stream != "" {