cs/main.go

43 lines
727 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
)
2017-05-21 15:38:41 -07:00
var algo = flag.String("a", "sha256", "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")
2017-10-18 17:58:11 -07:00
var verbose = flag.Bool("v", false, "vebose")
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
2017-10-18 17:58:11 -07:00
for err := range check(files, *verbose) {
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
2017-10-18 17:58:11 -07:00
for res := range hsh(files, *verbose) {
2016-11-16 00:52:39 -08:00
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 {
2018-02-27 20:29:40 -08:00
fmt.Printf("%v\t%v\n", res.cs, res.f)
2016-11-16 00:52:39 -08:00
}
}
2016-11-16 01:17:41 -08:00
if ec > 0 {
2016-11-15 20:24:15 -08:00
os.Exit(1)
}
}
}