Skip to content

Commit 5c10cda

Browse files
committed
feat: implement batch mode
1 parent 4411cb4 commit 5c10cda

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

main.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bufio"
55
"fmt"
66
"os"
7+
"path/filepath"
78
"regexp"
89
"strings"
910
)
@@ -62,6 +63,7 @@ func handleLine(input string) {
6263
}
6364

6465
func processFile(fileName string) int {
66+
fmt.Printf("\nReading file: %s\n", fileName)
6567
file, err := os.Open(fileName)
6668
if err != nil {
6769
fmt.Printf("Error reading file: %s.\n", err.Error())
@@ -92,6 +94,37 @@ func main() {
9294
os.Exit(1)
9395
}
9496

95-
var fileName string = arguments[1]
96-
os.Exit(processFile(fileName))
97+
if strings.Contains(arguments[1], ".scl") {
98+
var fileName string = arguments[1]
99+
os.Exit(processFile(fileName))
100+
}
101+
102+
if strings.Contains(arguments[1], "--batch") {
103+
var errorCounter int
104+
err := filepath.WalkDir("./", func(path string, dirEntry os.DirEntry, err error) error {
105+
if err != nil {
106+
return err
107+
}
108+
if !dirEntry.IsDir() && filepath.Ext(dirEntry.Name()) == ".scl" {
109+
errorCounter += processFile(path)
110+
}
111+
112+
return nil
113+
})
114+
115+
if errorCounter > 0 {
116+
fmt.Printf("Coding standards not met.\n")
117+
os.Exit(1)
118+
}
119+
120+
if err != nil {
121+
fmt.Printf("Error in batch processing: %v \n", err)
122+
os.Exit(1)
123+
}
124+
125+
}
126+
127+
fmt.Printf("Unexpected parameters.\n")
128+
os.Exit(1)
129+
97130
}

0 commit comments

Comments
 (0)