Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commands: fix a bunch of tiny commands-lib issues #5697

Merged
merged 1 commit into from
Oct 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/commands/dag/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ format.
}
out = final
}
return res.Emit(&out)
return cmds.EmitOnce(res, &out)
},
}

Expand Down Expand Up @@ -219,7 +219,7 @@ var DagResolveCmd = &cmds.Command{
return err
}

return res.Emit(&ResolveOutput{
return cmds.EmitOnce(res, &ResolveOutput{
Cid: lastCid,
RemPath: path.Join(rem),
})
Expand Down
2 changes: 1 addition & 1 deletion core/commands/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ The resolver can recursively resolve:
if err != nil {
return err
}
return res.Emit(&ncmd.ResolvedPath{Path: output})
return cmds.EmitOnce(res, &ncmd.ResolvedPath{Path: output})
},
Encoders: cmds.EncoderMap{
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *ncmd.ResolvedPath) error {
Expand Down
6 changes: 4 additions & 2 deletions core/commands/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,14 @@ This command outputs data in the following encodings:
return err
}

res.Emit(&pubsubMessage{
if err := res.Emit(&pubsubMessage{
Data: msg.Data(),
From: []byte(msg.From()),
Seqno: msg.Seq(),
TopicIDs: msg.Topics(),
})
}); err != nil {
return err
}
}
},
Encoders: cmds.EncoderMap{
Expand Down
14 changes: 10 additions & 4 deletions core/commands/stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,28 @@ Example:
for {
if pfound {
stats := nd.Reporter.GetBandwidthForPeer(pid)
res.Emit(&stats)
if err := res.Emit(&stats); err != nil {
return err
}
} else if tfound {
protoId := protocol.ID(tstr)
stats := nd.Reporter.GetBandwidthForProtocol(protoId)
res.Emit(&stats)
if err := res.Emit(&stats); err != nil {
return err
}
} else {
totals := nd.Reporter.GetBandwidthTotals()
res.Emit(&totals)
if err := res.Emit(&totals); err != nil {
return err
}
}
if !doPoll {
return nil
}
select {
case <-time.After(interval):
case <-req.Context.Done():
return nil
return req.Context.Err()
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion core/commands/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ represent it.
c := node.Cid()

fi.FileName()
return res.Emit(&coreiface.AddEvent{
return cmds.EmitOnce(res, &coreiface.AddEvent{
Name: fi.FileName(),
Hash: c.String(),
})
Expand Down
2 changes: 1 addition & 1 deletion core/commands/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var VersionCmd = &cmds.Command{
cmdkit.BoolOption(versionAllOptionName, "Show all version information"),
},
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
return res.Emit(&VersionOutput{
return cmds.EmitOnce(res, &VersionOutput{
Version: version.CurrentVersionNumber,
Commit: version.CurrentCommit,
Repo: fmt.Sprint(fsrepo.RepoVersion),
Expand Down