@@ -14,6 +14,7 @@ import (
14
14
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
15
15
manet "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr-net"
16
16
17
+ context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
17
18
cmds "github.com/jbenet/go-ipfs/commands"
18
19
cmdsCli "github.com/jbenet/go-ipfs/commands/cli"
19
20
cmdsHttp "github.com/jbenet/go-ipfs/commands/http"
@@ -53,6 +54,7 @@ type cmdInvocation struct {
53
54
// - output the response
54
55
// - if anything fails, print error, maybe with help
55
56
func main () {
57
+ ctx := context .Background ()
56
58
var err error
57
59
var invoc cmdInvocation
58
60
defer invoc .close ()
@@ -114,7 +116,7 @@ func main() {
114
116
}
115
117
116
118
// ok, finally, run the command invocation.
117
- output , err := invoc .Run ()
119
+ output , err := invoc .Run (ctx )
118
120
if err != nil {
119
121
printErr (err )
120
122
@@ -129,7 +131,7 @@ func main() {
129
131
io .Copy (os .Stdout , output )
130
132
}
131
133
132
- func (i * cmdInvocation ) Run () (output io.Reader , err error ) {
134
+ func (i * cmdInvocation ) Run (ctx context. Context ) (output io.Reader , err error ) {
133
135
// setup our global interrupt handler.
134
136
i .setupInterruptHandler ()
135
137
@@ -153,7 +155,7 @@ func (i *cmdInvocation) Run() (output io.Reader, err error) {
153
155
defer stopProfilingFunc () // to be executed as late as possible
154
156
}
155
157
156
- res , err := callCommand (i .req , Root )
158
+ res , err := callCommand (ctx , i .req , Root )
157
159
if err != nil {
158
160
return nil , err
159
161
}
@@ -243,8 +245,9 @@ func (i *cmdInvocation) requestedHelp() (short bool, long bool, err error) {
243
245
return longHelp , shortHelp , nil
244
246
}
245
247
246
- func callPreCommandHooks (details cmdDetails , req cmds.Request , root * cmds.Command ) error {
248
+ func callPreCommandHooks (ctx context. Context , details cmdDetails , req cmds.Request , root * cmds.Command ) error {
247
249
250
+ log .Event (ctx , "callPreCommandHooks" , & details )
248
251
log .Debug ("Calling pre-command hooks..." )
249
252
250
253
// some hooks only run when the command is executed locally
@@ -284,7 +287,7 @@ func callPreCommandHooks(details cmdDetails, req cmds.Request, root *cmds.Comman
284
287
return nil
285
288
}
286
289
287
- func callCommand (req cmds.Request , root * cmds.Command ) (cmds.Response , error ) {
290
+ func callCommand (ctx context. Context , req cmds.Request , root * cmds.Command ) (cmds.Response , error ) {
288
291
var res cmds.Response
289
292
290
293
details , err := commandDetails (req .Path (), root )
@@ -297,7 +300,7 @@ func callCommand(req cmds.Request, root *cmds.Command) (cmds.Response, error) {
297
300
return nil , err
298
301
}
299
302
300
- err = callPreCommandHooks (* details , req , root )
303
+ err = callPreCommandHooks (ctx , * details , req , root )
301
304
if err != nil {
302
305
return nil , err
303
306
}
0 commit comments