2015-12-08 10:18:42 -08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2016-11-15 21:28:01 -08:00
|
|
|
"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")
|
2018-03-23 09:27:06 -07:00
|
|
|
var recursive = flag.Bool("r", false, "recursive")
|
2016-11-15 21:28:01 -08:00
|
|
|
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
|
2018-03-23 09:27:06 -07:00
|
|
|
for res := range hsh(files, *verbose, *recursive) {
|
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 {
|
2017-10-18 17:42:31 -07:00
|
|
|
fmt.Printf("%v %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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|