@cryptotaxi247 / kubo / commits / 7a4031ddb

"pin verify": add --verbose and --quiet options

License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>

Kevin Atkinson committed Mar 30, 2017 at 00:49 UTC 7a4031ddb7855b5ccbdbe2a8fc435d3ff4eb6b77
1 file changed +21 -4
core/commands/pin.go
+21 -4
@@ -415,8 +415,19 @@ var verifyPinCmd = &cmds.Command{
415 Helptext: cmds.HelpText{
416 Tagline: "Verify that recursive pins are complete.",
417 },
418 + Options: []cmds.Option{
419 + cmds.BoolOption("verbose", "Also write the hashes of non-broken pins."),
420 + cmds.BoolOption("quiet", "q", "Write just hashes of broken pins."),
421 + },
422 Run: func(req cmds.Request, res cmds.Response) {
419 - n, _ := req.InvocContext().GetNode()
423 + n, err := req.InvocContext().GetNode()
424 + if err != nil {
425 + res.SetError(err, cmds.ErrNormal)
426 + return
427 + }
428 +
429 + verbose, _, _ := res.Request().Option("verbose").Bool()
430 + quiet, _, _ := res.Request().Option("quiet").Bool()
431
432 rdr, wtr := io.Pipe()
433 out := pinVerify(req.Context(), n)
@@ -424,7 +435,11 @@ var verifyPinCmd = &cmds.Command{
435 go func() {
436 defer wtr.Close()
437 for r := range out {
427 - r.Format(wtr)
438 + if quiet && len(r.badNodes) > 0 {
439 + fmt.Fprintf(wtr, "%s\n", r.cid)
440 + } else if !quiet {
441 + r.Format(wtr, verbose)
442 + }
443 }
444 }()
445
@@ -571,9 +586,11 @@ func pinVerify(ctx context.Context, n *core.IpfsNode) <-chan pinVerifyRes {
586 return out
587 }
588
574 -func (r pinVerifyRes) Format(out io.Writer) {
589 +func (r pinVerifyRes) Format(out io.Writer, verbose bool) {
590 if len(r.badNodes) == 0 {
576 - fmt.Fprintf(out, "%s ok\n", r.cid)
591 + if verbose {
592 + fmt.Fprintf(out, "%s ok\n", r.cid)
593 + }
594 } else {
595 fmt.Fprintf(out, "%s broken\n", r.cid)
596 for _, e := range r.badNodes {