Skip to content

Commit

Permalink
Sync output for SKIP logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Abroskin committed Dec 14, 2019
1 parent e898b5c commit 68c6a90
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 23 deletions.
40 changes: 27 additions & 13 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ func executeCommand(hooksGroup, commandName string, wg *sync.WaitGroup) {
defer wg.Done()

if getPiped(hooksGroup) && isPipeBroken {
log.Println(au.Cyan("\n EXECUTE >"), au.Bold(commandName))
log.Println(au.Brown("(SKIP BY BROKEN PIPE)"))
mutex.Lock()
log.Println("\n", au.Bold(commandName), au.Brown("(SKIP BY BROKEN PIPE)"))
mutex.Unlock()
return
}

Expand Down Expand Up @@ -210,22 +211,28 @@ func executeCommand(hooksGroup, commandName string, wg *sync.WaitGroup) {
runner = strings.Replace(runner, subAllFiles, strings.Join(files, " "), -1)
runner = strings.Replace(runner, subFiles, strings.Join(files, " "), -1)

command := exec.Command("sh", "-c", runner)
command.Stdin = os.Stdin

if isSkipCommmand(hooksGroup, commandName) {
log.Println(au.Bold(commandName), au.Brown("(SKIP BY SETTINGS)"))
mutex.Lock()
log.Println("\n", au.Bold(commandName), au.Brown("(SKIP BY SETTINGS)"))
mutex.Unlock()
return
}
if result, _ := arrop.Intersect(getExcludeTags(hooksGroup), getTags(hooksGroup, commandsConfigKey, commandName)); len(result.Interface().([]string)) > 0 {
log.Println(au.Bold(commandName), au.Brown("(SKIP BY TAGS)"))
mutex.Lock()
log.Println("\n", au.Bold(commandName), au.Brown("(SKIP BY TAGS)"))
mutex.Unlock()
return
}
if len(files) < 1 && isSkipEmptyCommmand(hooksGroup, commandName) {
log.Println(au.Bold(commandName), au.Brown("(SKIP. NO FILES FOR INSPECTING)"))
mutex.Lock()
log.Println("\n", au.Bold(commandName), au.Brown("(SKIP. NO FILES FOR INSPECTING)"))
mutex.Unlock()
return
}

command := exec.Command("sh", "-c", runner)
command.Stdin = os.Stdin

ptyOut, err := pty.Start(command)
mutex.Lock()
defer mutex.Unlock()
Expand Down Expand Up @@ -258,8 +265,9 @@ func executeScript(hooksGroup, source string, executable os.FileInfo, wg *sync.W
executableName := executable.Name()

if getPiped(hooksGroup) && isPipeBroken {
log.Println(au.Cyan("\n EXECUTE >"), au.Bold(executableName))
log.Println(au.Brown("(SKIP BY BROKEN PIPE)"))
mutex.Lock()
log.Println("\n", au.Bold(executableName), au.Brown("(SKIP BY BROKEN PIPE)"))
mutex.Unlock()
return
}

Expand All @@ -282,15 +290,21 @@ func executeScript(hooksGroup, source string, executable os.FileInfo, wg *sync.W
}

if !isScriptExist(hooksGroup, executableName) {
log.Println(au.Bold(executableName), au.Brown("(SKIP BY NOT EXIST IN CONFIG)"))
mutex.Lock()
log.Println("\n", au.Bold(executableName), au.Brown("(SKIP BY NOT EXIST IN CONFIG)"))
mutex.Unlock()
return
}
if isSkipScript(hooksGroup, executableName) {
log.Println(au.Bold(executableName), au.Brown("(SKIP BY SETTINGS)"))
mutex.Lock()
log.Println("\n", au.Bold(executableName), au.Brown("(SKIP BY SETTINGS)"))
mutex.Unlock()
return
}
if result, _ := arrop.Intersect(getExcludeTags(hooksGroup), getTags(hooksGroup, scriptsConfigKey, executableName)); len(result.Interface().([]string)) > 0 {
log.Println(au.Bold(executableName), au.Brown("(SKIP BY TAGS)"))
mutex.Lock()
log.Println("\n", au.Bold(executableName), au.Brown("(SKIP BY TAGS)"))
mutex.Unlock()
return
}

Expand Down
34 changes: 24 additions & 10 deletions cmd/run_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ func executeCommand(hooksGroup, commandName string, wg *sync.WaitGroup) {
defer wg.Done()

if getPiped(hooksGroup) && isPipeBroken {
log.Println(au.Cyan("\n EXECUTE >"), au.Bold(commandName))
log.Println(au.Brown("(SKIP BY BROKEN PIPE)"))
mutex.Lock()
log.Println("\n", au.Bold(commandName), au.Brown("(SKIP BY BROKEN PIPE)"))
mutex.Unlock()
return
}

Expand Down Expand Up @@ -206,15 +207,21 @@ func executeCommand(hooksGroup, commandName string, wg *sync.WaitGroup) {
runner = strings.Replace(runner, subFiles, strings.Join(files, " "), -1)

if isSkipCommmand(hooksGroup, commandName) {
log.Println(au.Bold(commandName), au.Brown("(SKIP BY SETTINGS)"))
mutex.Lock()
log.Println("\n", au.Bold(commandName), au.Brown("(SKIP BY SETTINGS)"))
mutex.Unlock()
return
}
if result, _ := arrop.Intersect(getExcludeTags(hooksGroup), getTags(hooksGroup, commandsConfigKey, commandName)); len(result.Interface().([]string)) > 0 {
log.Println(au.Bold(commandName), au.Brown("(SKIP BY TAGS)"))
mutex.Lock()
log.Println("\n", au.Bold(commandName), au.Brown("(SKIP BY TAGS)"))
mutex.Unlock()
return
}
if len(files) < 1 && isSkipEmptyCommmand(hooksGroup, commandName) {
log.Println(au.Bold(commandName), au.Brown("(SKIP. NO FILES FOR INSPECTING)"))
mutex.Lock()
log.Println("\n", au.Bold(commandName), au.Brown("(SKIP. NO FILES FOR INSPECTING)"))
mutex.Unlock()
return
}

Expand Down Expand Up @@ -250,8 +257,9 @@ func executeScript(hooksGroup, source string, executable os.FileInfo, wg *sync.W
executableName := executable.Name()

if getPiped(hooksGroup) && isPipeBroken {
log.Println(au.Cyan("\n EXECUTE >"), au.Bold(executableName))
log.Println(au.Brown("(SKIP BY BROKEN PIPE)"))
mutex.Lock()
log.Println("\n", au.Bold(executableName), au.Brown("(SKIP BY BROKEN PIPE)"))
mutex.Unlock()
return
}

Expand All @@ -277,15 +285,21 @@ func executeScript(hooksGroup, source string, executable os.FileInfo, wg *sync.W
command.Stderr = os.Stderr // win specific

if !isScriptExist(hooksGroup, executableName) {
log.Println(au.Bold(executableName), au.Brown("(SKIP BY NOT EXIST IN CONFIG)"))
mutex.Lock()
log.Println("\n", au.Bold(executableName), au.Brown("(SKIP BY NOT EXIST IN CONFIG)"))
mutex.Unlock()
return
}
if isSkipScript(hooksGroup, executableName) {
log.Println(au.Bold(executableName), au.Brown("(SKIP BY SETTINGS)"))
mutex.Lock()
log.Println("\n", au.Bold(executableName), au.Brown("(SKIP BY SETTINGS)"))
mutex.Unlock()
return
}
if result, _ := arrop.Intersect(getExcludeTags(hooksGroup), getTags(hooksGroup, scriptsConfigKey, executableName)); len(result.Interface().([]string)) > 0 {
log.Println(au.Bold(executableName), au.Brown("(SKIP BY TAGS)"))
mutex.Lock()
log.Println("\n", au.Bold(executableName), au.Brown("(SKIP BY TAGS)"))
mutex.Unlock()
return
}

Expand Down

0 comments on commit 68c6a90

Please sign in to comment.