@cryptotaxi247 / kubo / commits / b5dc686fd

feat(main) create root context

License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com>

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