feat: add a text output encoding for the stats provide command
Adin Schmahmann committed
May 25, 2021 at 17:47 UTC
37de3d0586928a3d3373a07c864d4d894d4de276
1 file changed
+15
-2
core/commands/stat_provide.go
+15
-2
@@ -2,6 +2,8 @@ package commands
2
3
import (
4
"fmt"
5
+ "io"
6
+ "text/tabwriter"
7
8
cmds "github.com/ipfs/go-ipfs-cmds"
9
"github.com/ipfs/go-ipfs/core/commands/cmdenv"
@@ -46,6 +48,17 @@ This interface is not stable and may change from release to release.
48
49
return nil
50
},
49
- Encoders: cmds.EncoderMap{},
50
- Type: batched.BatchedProviderStats{},
51
+ Encoders: cmds.EncoderMap{
52
+ cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, s *batched.BatchedProviderStats) error {
53
+ wtr := tabwriter.NewWriter(w, 0, 0, 1, ' ', 0)
54
+ defer wtr.Flush()
55
+
56
+ fmt.Fprintf(wtr, "TotalProvides: %d\n", s.TotalProvides)
57
+ fmt.Fprintf(wtr, "AvgProvideDuration: %v\n", s.AvgProvideDuration)
58
+ fmt.Fprintf(wtr, "LastReprovideDuration: %v\n", s.LastReprovideDuration)
59
+ fmt.Fprintf(wtr, "LastReprovideBatchSize: %d\n", s.LastReprovideBatchSize)
60
+ return nil
61
+ }),
62
+ },
63
+ Type: batched.BatchedProviderStats{},
64
}