Skip to content

Commit 37de3d0

Browse files
committed
feat: add a text output encoding for the stats provide command
1 parent 3746c2d commit 37de3d0

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

core/commands/stat_provide.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package commands
22

33
import (
44
"fmt"
5+
"io"
6+
"text/tabwriter"
57

68
cmds "github.com/ipfs/go-ipfs-cmds"
79
"github.com/ipfs/go-ipfs/core/commands/cmdenv"
@@ -46,6 +48,17 @@ This interface is not stable and may change from release to release.
4648

4749
return nil
4850
},
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{},
5164
}

0 commit comments

Comments
 (0)