start/stop workflow improved

This commit is contained in:
alessio 2016-08-19 22:52:53 +02:00
parent 19d0b04c73
commit dfec8209f3
3 changed files with 19 additions and 33 deletions

View File

@ -43,6 +43,7 @@ func New(params *cli.Context) *Config {
func Duplicates(value Project, arr []Project) bool {
for _, val := range arr {
if value.Main == val.Main && value.Path == val.Path || value.Name == val.Name {
Fail("There is a duplicate of '"+val.Name+"'. Check your config file!")
return true
}
}
@ -109,6 +110,7 @@ func (h *Config) Add(params *cli.Context) error {
Path: params.String("base"),
Run: params.Bool("run"),
Build: params.Bool("build"),
Bin: params.Bool("bin"),
Watcher: Watcher{
Paths: watcherPaths,
Exts: watcherExts,

View File

@ -33,7 +33,7 @@ func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
if len(name) == 1 {
name := strings.Split(p.base, "/")
run = name[len(name)-1]
} else {
}else {
run = name[len(name)-1]
}
build := exec.Command(os.Getenv("GOPATH") + slash("bin") + slash(run))
@ -60,7 +60,7 @@ func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
for in.Scan() {
select {
default:
log.Println(p.Name+":", in.Text())
log.Println(bluel(p.Name+":"), bluel(in.Text()))
}
}
close(stop)

View File

@ -70,16 +70,12 @@ func (p *Project) Watching() {
channel = make(chan bool)
wr.Add(1)
go p.build()
go p.install(&wr)
wr.Wait()
wr.Add(1)
p.run(channel, &wr)
go p.install(channel,&wr)
}
end := func() {
watcher.Close()
wg.Done()
}
defer end()
p.Main = slash(p.Main)
@ -103,11 +99,8 @@ func (p *Project) Watching() {
}
}
routines()
fmt.Println(red("\n Watching: '" + p.Name + "'\n"))
p.reload = time.Now().Truncate(time.Second)
for {
select {
case event := <-watcher.Events:
@ -134,16 +127,28 @@ func (p *Project) Watching() {
}
// Install call an implementation of the "go install"
func (p *Project) install(wr *sync.WaitGroup) {
func (p *Project) install(channel chan bool,wr *sync.WaitGroup) {
if p.Bin {
LogSuccess(p.Name + ": Installing..")
if err := p.GoInstall(); err != nil {
Fail(err.Error())
wr.Done()
} else {
LogSuccess(p.Name + ": Installed")
if p.Run {
runner := make(chan bool, 1)
LogSuccess(p.Name + ": Running..")
go p.GoRun(channel, runner, wr)
for {
select {
case <-runner:
LogSuccess(p.Name + ": Runned")
return
}
}
}
}
}
wr.Done()
return
}
@ -161,27 +166,6 @@ func (p *Project) build() {
return
}
// Build call an implementation of the bin execution
func (p *Project) run(channel chan bool, wr *sync.WaitGroup) {
if p.Run {
if p.Bin {
runner := make(chan bool, 1)
LogSuccess(p.Name + ": Running..")
go p.GoRun(channel, runner, wr)
for {
select {
case <-runner:
LogSuccess(p.Name + ": Runned")
return
}
}
} else {
LogFail("Set 'app_run' to true for launch run")
}
}
return
}
// Ignore validates a path
func (p *Project) ignore(str string) bool {
for _, v := range p.Watcher.Ignore {