diff --git a/internal/processing/walk.go b/internal/processing/walk.go index 5556a0e..2a2647a 100644 --- a/internal/processing/walk.go +++ b/internal/processing/walk.go @@ -11,6 +11,21 @@ import ( // ChannelBuffering is the size of file processing results queue const ChannelBuffering = 10 +func printGrepResults(processedChannel chan models.FileMatchData, expectedItems int) error { + for ; expectedItems > 0; expectedItems-- { + curProcessed := <-processedChannel + if len(curProcessed.Lines) == 0 { + continue + } + fmt.Printf("%s:\n", curProcessed.Path) + for i := 0; i < len(curProcessed.Lines); i++ { + fmt.Printf("%d:%s\n", curProcessed.LineIndexes[i], curProcessed.Lines[i]) + } + fmt.Print("\n") + } + return nil +} + // DoGrepMain performs full grep accorgind to config and root func DoGrepMain(config *models.GrepConfigInternal, root string) error { processedChannel := make(chan models.FileMatchData, ChannelBuffering) @@ -31,16 +46,12 @@ func DoGrepMain(config *models.GrepConfigInternal, root string) error { return nil }) - for ; totalFiles > 0; totalFiles-- { - curProcessed := <-processedChannel - if len(curProcessed.Lines) == 0 { - continue - } - fmt.Printf("%s:\n", curProcessed.Path) - for i := 0; i < len(curProcessed.Lines); i++ { - fmt.Printf("%d:%s\n", curProcessed.LineIndexes[i], curProcessed.Lines[i]) - } - fmt.Print("\n") + if err != nil { + return err + } + err = printGrepResults(processedChannel, totalFiles) + if err != nil { + return err } return err }