refactor: split color func from runGoTest
parent
4467751b1a
commit
c72f25c2db
31
main.go
31
main.go
|
@ -33,10 +33,20 @@ func runGoTest() int {
|
|||
cmd.Stdout = outWriter
|
||||
cmd.Stderr = errWriter
|
||||
|
||||
go func() {
|
||||
defer outReader.Close()
|
||||
go colorOutputReader(outReader)
|
||||
go colorErrorReader(errReader)
|
||||
|
||||
scanner := bufio.NewScanner(outReader)
|
||||
if err := cmd.Run(); err != nil {
|
||||
return 1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
func colorOutputReader(reader io.ReadCloser) {
|
||||
defer reader.Close()
|
||||
|
||||
scanner := bufio.NewScanner(reader)
|
||||
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
|
@ -61,12 +71,12 @@ func runGoTest() int {
|
|||
if err := scanner.Err(); err != nil {
|
||||
log.Printf("scanner error: %s", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
go func() {
|
||||
defer errReader.Close()
|
||||
func colorErrorReader(reader io.ReadCloser) {
|
||||
defer reader.Close()
|
||||
|
||||
scanner := bufio.NewScanner(errReader)
|
||||
scanner := bufio.NewScanner(reader)
|
||||
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
|
@ -76,11 +86,4 @@ func runGoTest() int {
|
|||
if err := scanner.Err(); err != nil {
|
||||
log.Printf("scanner error: %s", err)
|
||||
}
|
||||
}()
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
return 1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue