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

View File

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

View File

@ -61,9 +61,9 @@ type tool struct {
// Cmds go supported
type Cmds struct {
Vet bool `yaml:"vet,omitempty" json:"vet,omitempty"`
Fmt bool `yaml:"fmt,omitempty" json:"fmt,omitempty"`
Test bool `yaml:"test,omitempty" json:"test,omitempty"`
Generate bool `yaml:"generate,omitempty" json:"generate,omitempty"`
Fmt Cmd `yaml:"fmt,omitempty" json:"fmt,omitempty"`
Test Cmd `yaml:"test,omitempty" json:"test,omitempty"`
Generate Cmd `yaml:"generate,omitempty" json:"generate,omitempty"`
Bin Cmd `yaml:"bin" json:"bin"`
Build Cmd `yaml:"build,omitempty" json:"build,omitempty"`
Run bool `yaml:"run,omitempty" json:"run,omitempty"`
@ -90,6 +90,7 @@ type Command struct {
Command string `yaml:"command" json:"command"`
Path string `yaml:"path,omitempty" json:"path,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

View File

@ -9,6 +9,7 @@ import (
"github.com/tockins/realize/style"
cli "gopkg.in/urfave/cli.v2"
"strings"
)
// Argsparam parse one by one the given argumentes
@ -57,3 +58,12 @@ func getEnvPath(env string) string {
}
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 {
p.stamp("log", out, msg, "")
}
if logs != "" {
if logs != "" && cmd.Output {
msg = fmt.Sprintln(logs)
out = BufferOut{Time: time.Now(), Text: logs, Type: flag}
p.stamp("log", out, "", msg)
@ -316,8 +316,8 @@ func (p *Project) ignore(str string) bool {
// Routines launches the toolchain run, build, install
func (p *Project) routines(wr *sync.WaitGroup, channel chan bool, watcher watcher, file string) {
if len(file) > 0 {
p.cmd("before", false)
if len(file) > 0 {
path := filepath.Dir(file)
p.tool(file, p.tools.Fmt)
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 {
p.cmd("after", false)
}
}
// 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 {
case "out":
p.Buffer.StdOut = append(p.Buffer.StdOut, o)
if p.Resources.Outputs.Status {
f := p.Create(p.base, p.Resources.Outputs.Name)
if p.Files.Outputs.Status {
f := p.Create(p.base, p.Files.Outputs.Name)
t := time.Now()
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 {
@ -376,8 +375,8 @@ func (p *Project) stamp(t string, o BufferOut, msg string, stream string) {
}
case "log":
p.Buffer.StdLog = append(p.Buffer.StdLog, o)
if p.Resources.Logs.Status {
f := p.Create(p.base, p.Resources.Logs.Name)
if p.Files.Logs.Status {
f := p.Create(p.base, p.Files.Logs.Name)
t := time.Now()
s := []string{t.Format("2006-01-02 15:04:05"), strings.ToUpper(p.Name), ":", o.Text, "\r\n"}
if stream != "" {
@ -389,8 +388,8 @@ func (p *Project) stamp(t string, o BufferOut, msg string, stream string) {
}
case "error":
p.Buffer.StdErr = append(p.Buffer.StdErr, o)
if p.Resources.Errors.Status {
f := p.Create(p.base, p.Resources.Errors.Name)
if p.Files.Errors.Status {
f := p.Create(p.base, p.Files.Errors.Name)
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"}
if stream != "" {