增加 ignore*指令支持

This commit is contained in:
dengsgo 2020-01-02 17:38:52 +08:00
parent 3351429515
commit 1b4206a6b3
3 changed files with 21 additions and 2 deletions

View File

@ -18,8 +18,12 @@ import (
const ( const (
Version = 1 Version = 1
InstExecWhenStart = "exec-when-start" InstExecWhenStart = "exec-when-start"
InstShouldFinish = "should-finish" InstShouldFinish = "should-finish"
InstIgnoreWarn = "ignore-warn"
InstIgnoreInfo = "ignore-info"
InstIgnoreStdout = "ignore-stdout"
InstIgnoreExecError = "ignore-exec-error"
) )
var ( var (

View File

@ -93,17 +93,26 @@ func (t *TaskMan) run(cf *changedFile) {
//cmd.SysProcAttr = &syscall.SysProcAttr{CreationFlags: syscall.CREATE_UNICODE_ENVIRONMENT} //cmd.SysProcAttr = &syscall.SysProcAttr{CreationFlags: syscall.CREATE_UNICODE_ENVIRONMENT}
t.cmd.Stdin = os.Stdin t.cmd.Stdin = os.Stdin
t.cmd.Stdout = os.Stdout t.cmd.Stdout = os.Stdout
if keyInInstruction(InstIgnoreStdout) {
t.cmd.Stdout = nil
}
t.cmd.Stderr = os.Stderr t.cmd.Stderr = os.Stderr
t.cmd.Dir = projectFolder t.cmd.Dir = projectFolder
t.cmd.Env = os.Environ() t.cmd.Env = os.Environ()
err := t.cmd.Start() err := t.cmd.Start()
if err != nil { if err != nil {
logError("run command", carr, "error. ", err) logError("run command", carr, "error. ", err)
if keyInInstruction(InstIgnoreExecError) {
continue
}
break break
} }
err = t.cmd.Wait() err = t.cmd.Wait()
if err != nil { if err != nil {
logWarn("command exec failed:", carr, err) logWarn("command exec failed:", carr, err)
if keyInInstruction(InstIgnoreExecError) {
continue
}
break break
} }
if t.cmd.Process != nil { if t.cmd.Process != nil {

View File

@ -82,11 +82,17 @@ func inStrArray(s string, arr []string) bool {
} }
func logInfo(v ...interface{}) { func logInfo(v ...interface{}) {
if keyInInstruction(InstIgnoreInfo) {
return
}
v = append([]interface{}{"I:"}, v...) v = append([]interface{}{"I:"}, v...)
log.Println(v...) log.Println(v...)
} }
func logWarn(v ...interface{}) { func logWarn(v ...interface{}) {
if keyInInstruction(InstIgnoreWarn) {
return
}
v = append([]interface{}{"W:"}, v...) v = append([]interface{}{"W:"}, v...)
log.Println(v...) log.Println(v...)
} }