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 27, 2021
1 parent 3746c2d commit 37de3d0
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions core/commands/stat_provide.go
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 37de3d0

Please sign in to comment.