From eff877f1193b197cebcfe4690acb5665c3f1d340 Mon Sep 17 00:00:00 2001 From: Overbool Date: Wed, 5 Dec 2018 14:34:20 +0800 Subject: [PATCH] feat(cmds): hide peers info default in bitswap stat License: MIT Signed-off-by: Overbool --- core/commands/bitswap.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/core/commands/bitswap.go b/core/commands/bitswap.go index 84f85c457d3c..da462960152e 100644 --- a/core/commands/bitswap.go +++ b/core/commands/bitswap.go @@ -85,11 +85,18 @@ Print out all blocks currently on the bitswap wantlist for the local peer.`, }, } +const ( + bitswapVerboseOptionName = "verbose" +) + var bitswapStatCmd = &cmds.Command{ Helptext: cmdkit.HelpText{ Tagline: "Show some diagnostic information on the bitswap agent.", ShortDescription: ``, }, + Options: []cmdkit.Option{ + cmdkit.BoolOption(bitswapVerboseOptionName, "v", "print extra information"), + }, Type: bitswap.Stat{}, Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { nd, err := cmdenv.GetNode(env) @@ -115,6 +122,8 @@ var bitswapStatCmd = &cmds.Command{ }, Encoders: cmds.EncoderMap{ cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, s *bitswap.Stat) error { + verbose, _ := req.Options[bitswapVerboseOptionName].(bool) + fmt.Fprintln(w, "bitswap status") fmt.Fprintf(w, "\tprovides buffer: %d / %d\n", s.ProvideBufLen, bitswap.HasBlockBufferSize) fmt.Fprintf(w, "\tblocks received: %d\n", s.BlocksReceived) @@ -127,9 +136,12 @@ var bitswapStatCmd = &cmds.Command{ for _, k := range s.Wantlist { fmt.Fprintf(w, "\t\t%s\n", k.String()) } + fmt.Fprintf(w, "\tpartners [%d]\n", len(s.Peers)) - for _, p := range s.Peers { - fmt.Fprintf(w, "\t\t%s\n", p) + if verbose { + for _, p := range s.Peers { + fmt.Fprintf(w, "\t\t%s\n", p) + } } return nil