-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
39 lines (32 loc) · 951 Bytes
/
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
package main
import (
"flag"
)
func main() {
var countLines, countWords, countBytes bool
var totalLines, totalWords, totalBytes int64
flag.BoolVar(&countLines, "l", false, "Count Lines")
flag.BoolVar(&countWords, "w", false, "Count Words")
flag.BoolVar(&countBytes, "c", false, "Count Bytes")
flag.Parse()
if !countLines && !countWords && !countBytes {
countLines = true
countWords = true
countBytes = true
}
if len(flag.Args()) == 0 {
lines, words, bytes := ProcessStream()
FormatPrint(countLines, countWords, countBytes, lines, words, bytes, "")
return
}
for _, fileName := range flag.Args() {
lines, words, bytes := ProcessFile(fileName)
FormatPrint(countLines, countWords, countBytes, lines, words, bytes, fileName)
totalLines += lines
totalWords += words
totalBytes += bytes
}
if len(flag.Args()) > 1 {
FormatPrint(countLines, countWords, countBytes, totalLines, totalWords, totalBytes, "total")
}
}