增加 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

@ -20,6 +20,10 @@ const (
InstExecWhenStart = "exec-when-start"
InstShouldFinish = "should-finish"
InstIgnoreWarn = "ignore-warn"
InstIgnoreInfo = "ignore-info"
InstIgnoreStdout = "ignore-stdout"
InstIgnoreExecError = "ignore-exec-error"
)
var (

View File

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

View File

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