init
This commit is contained in:
commit
7a6b109e78
4 changed files with 164 additions and 0 deletions
32
cmd/namecount/main.go
Normal file
32
cmd/namecount/main.go
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"tallin/internal/counter"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) != 2 {
|
||||
fmt.Fprintf(os.Stderr, "usage: %s <filename>\n", os.Args[0])
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
file, err := os.Open(os.Args[1])
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "open file: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
counts, err := counter.Count(file)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "read file: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
for _, result := range counter.Sorted(counts) {
|
||||
fmt.Printf("%s:%d\n", result.Name, result.Count)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue