Skip to content

Commit

Permalink
feat: add a text output encoding for the stats provide command
Browse files Browse the repository at this point in the history
  • Loading branch information
aschmahmann committed May 26, 2021
1 parent ed701a7 commit 64642b2
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions core/commands/stat_provide.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package commands

import (
"fmt"
"io"
"text/tabwriter"

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

return nil
},
Encoders: cmds.EncoderMap{},
Type: batched.BatchedProviderStats{},
Encoders: cmds.EncoderMap{
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, s *batched.BatchedProviderStats) error {
wtr := tabwriter.NewWriter(w, 0, 0, 1, ' ', 0)
defer wtr.Flush()

fmt.Fprintf(wtr, "TotalProvides: %d\n", s.TotalProvides)
fmt.Fprintf(wtr, "AvgProvideDuration: %v\n", s.AvgProvideDuration)
fmt.Fprintf(wtr, "LastReprovideDuration: %v\n", s.LastReprovideDuration)
fmt.Fprintf(wtr, "LastReprovideBatchSize: %d\n", s.LastReprovideBatchSize)
return nil
}),
},
Type: batched.BatchedProviderStats{},
}

0 comments on commit 64642b2

Please sign in to comment.