Skip to content

Commit cbe9a46

Browse files
committed
feat: function to process a file
1 parent 586c459 commit cbe9a46

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

main.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,11 @@ func handleLine(input string) {
6161
return
6262
}
6363

64-
func main() {
65-
if len(arguments) < 2 {
66-
fmt.Printf("Command needs an argument.\n")
67-
os.Exit(1)
68-
}
69-
var fileName string = arguments[1]
64+
func processFile(fileName string) int {
7065
file, err := os.Open(fileName)
7166
if err != nil {
7267
fmt.Printf("Error reading file: %s.\n", err.Error())
73-
os.Exit(1)
68+
return 1
7469
}
7570

7671
scanner := bufio.NewScanner(file)
@@ -86,7 +81,17 @@ func main() {
8681

8782
file.Close()
8883
if isErrorDetected == true {
84+
return 1
85+
}
86+
return 0
87+
}
88+
89+
func main() {
90+
if len(arguments) < 2 {
91+
fmt.Printf("Command needs an argument.\n")
8992
os.Exit(1)
9093
}
91-
os.Exit(0)
94+
95+
var fileName string = arguments[1]
96+
os.Exit(processFile(fileName))
9297
}

0 commit comments

Comments
 (0)