-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
47 lines (42 loc) · 1.38 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"fmt"
"github.com/Goku-kun/wc-golang/lib/fileprocessor"
"github.com/Goku-kun/wc-golang/lib/flagparser"
)
func main() {
flags, fileNames := flagparser.ParseFlags()
if len(fileNames) == 0 {
fileContent := fileprocessor.ReadPipe()
l := fileprocessor.CountLines(fileContent)
w := fileprocessor.CountWords(fileContent)
b := fileprocessor.CountBytes(fileContent)
if flags["c"] {
fmt.Printf(" %v\n", b)
} else if flags["l"] {
fmt.Printf(" %v\n", l)
} else if flags["w"] {
fmt.Printf(" %v\n", w)
} else {
fmt.Printf(" %v %v %v \n", l, w, b)
}
return
}
for _, fileName := range fileNames {
if flags["c"] {
b := fileprocessor.CountBytes(fileprocessor.OpenFileAndReadAllData(fileName))
fmt.Printf(" %v %v\n", b, fileName)
} else if flags["l"] {
l := fileprocessor.CountLines(fileprocessor.OpenFileAndReadAllData(fileName))
fmt.Printf(" %v %v\n", l, fileName)
} else if flags["w"] {
w := fileprocessor.CountWords(fileprocessor.OpenFileAndReadAllData(fileName))
fmt.Printf(" %v %v\n", w, fileName)
} else {
b := fileprocessor.CountBytes(fileprocessor.OpenFileAndReadAllData(fileName))
l := fileprocessor.CountLines(fileprocessor.OpenFileAndReadAllData(fileName))
w := fileprocessor.CountWords(fileprocessor.OpenFileAndReadAllData(fileName))
fmt.Printf(" %v %v %v %v\n", l, w, b, fileName)
}
}
}