cs/main.go

42 lines
649 B
Go
Raw Normal View History

2015-12-08 10:18:42 -08:00
package main
import (
"flag"
"fmt"
"os"
"runtime"
2015-12-08 10:18:42 -08:00
)
2015-12-10 14:46:06 -08:00
var algo = flag.String("a", "sha1", "algorithm to use")
2016-11-15 20:24:15 -08:00
var mode = flag.Bool("c", false, "check")
var ngo = flag.Int("n", runtime.NumCPU(), "number of goroutines")
2015-12-08 10:18:42 -08:00
func main() {
flag.Parse()
files := flag.Args()
2016-11-15 20:24:15 -08:00
switch *mode {
case true:
2016-11-16 01:17:41 -08:00
ec := 0
2016-11-15 20:50:04 -08:00
for err := range check(files) {
2016-11-16 01:17:41 -08:00
ec++
2016-11-15 20:24:15 -08:00
fmt.Fprintf(os.Stderr, "%v\n", err)
2016-11-15 20:50:04 -08:00
}
2016-11-16 01:17:41 -08:00
if ec > 0 {
2016-11-15 20:24:15 -08:00
os.Exit(1)
}
case false:
2016-11-16 01:17:41 -08:00
ec := 0
2016-11-16 00:52:39 -08:00
for res := range hsh(files) {
if res.err != nil {
2016-11-16 01:17:41 -08:00
ec++
2016-11-16 00:52:39 -08:00
fmt.Fprintf(os.Stderr, "%v\n", res.err)
} else {
fmt.Printf("%v\n", res.msg)
}
}
2016-11-16 01:17:41 -08:00
if ec > 0 {
2016-11-15 20:24:15 -08:00
os.Exit(1)
}
}
}