From 0a4b5eb1be29892504d3bc02c782e2cdc5cd6377 Mon Sep 17 00:00:00 2001 From: asoseil Date: Sun, 15 Oct 2017 22:21:29 +0200 Subject: [PATCH] #16 support for install and build --- cmd.go | 10 +++++++--- watcher.go | 13 ++++++++----- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/cmd.go b/cmd.go index 30ecd39..e8dad20 100644 --- a/cmd.go +++ b/cmd.go @@ -33,6 +33,8 @@ type Cmds struct { type Cmd struct { Status bool `yaml:"status,omitempty" json:"status,omitempty"` Args []string `yaml:"args,omitempty" json:"args,omitempty"` + Method []string `yaml:"method,omitempty" json:"method,omitempty"` + method []string name, startTxt, endTxt string } @@ -151,14 +153,16 @@ func (r *realize) run(p *cli.Context) error { // default settings r.Schema[k].Cmds.Install = Cmd{ Status: elm.Cmds.Install.Status, - Args: append([]string{"install"}, elm.Cmds.Install.Args...), + Args: append([]string{}, elm.Cmds.Install.Args...), + method: []string{"go", "install"}, name: "Go Install", startTxt: "Installing...", endTxt: "Installed", } r.Schema[k].Cmds.Build = Cmd{ Status: elm.Cmds.Build.Status, - Args: append([]string{"build"}, elm.Cmds.Build.Args...), + Args: append([]string{}, elm.Cmds.Build.Args...), + method: []string{"go", "build"}, name: "Go Build", startTxt: "Bulding...", endTxt: "Built", @@ -206,7 +210,7 @@ func (r *realize) remove(p *cli.Context) error { return errors.New("no project found") } -// Insert a project if there isn't already one +// Insert current project if there isn't already one func (r *realize) insert(c *cli.Context) error { if c.Bool("no-config") { r.Schema = []Project{} diff --git a/watcher.go b/watcher.go index ba2acad..b17c49e 100644 --- a/watcher.go +++ b/watcher.go @@ -21,12 +21,12 @@ var ( wg sync.WaitGroup ) -// Watcher struct defines the livereload's logic +// Watch struct defines options for livereload type Watch struct { + Preview bool `yaml:"preview,omitempty" json:"preview,omitempty"` Paths []string `yaml:"paths" json:"paths"` Exts []string `yaml:"extensions" json:"extensions"` Ignore []string `yaml:"ignored_paths,omitempty" json:"ignored_paths,omitempty"` - Preview bool `yaml:"preview,omitempty" json:"preview,omitempty"` Scripts []Command `yaml:"scripts,omitempty" json:"scripts,omitempty"` } @@ -83,7 +83,7 @@ type BufferOut struct { Errors []string `json:"errors"` } -// Watch the project by fsnotify +// Watch the project func (p *Project) watch() { p.watcher, _ = Watcher() stop, exit := make(chan bool), make(chan os.Signal, 2) @@ -166,7 +166,7 @@ func (p *Project) err(err error) { p.stamp("error", out, msg, "") } -// Cmd calls an wrapper for execute the commands after/before +// Cmd calls the method that execute commands after/before and display the results func (p *Project) cmd(stop <-chan bool, flag string, global bool) { done := make(chan bool) // cmds are scheduled in sequence @@ -214,7 +214,10 @@ func (p *Project) compile(stop <-chan bool, cmd Cmd) error { channel := make(chan Result) go func() { log.Println(p.pname(p.Name, 1), ":", cmd.startTxt) - stream, err := p.goCompile(stop, cmd.Args) + if len(cmd.Method) > 0 { + cmd.method = cmd.Method + } + stream, err := p.goCompile(stop, cmd.method, cmd.Args) if stream != "killed" { channel <- Result{stream, err} }