@cryptotaxi247 / kubo / commits / 1281b2510

commands: Added PostRun function, called on the client

Matt Bell committed Jan 20, 2015 at 19:03 UTC 1281b251058fdfce67e105efe0b02f63a2a854ce
2 files changed +8 -2
cmd/ipfs/main.go
+7 -2
@@ -158,7 +158,7 @@ func (i *cmdInvocation) Run(ctx context.Context) (output io.Reader, err error) {
158 defer stopProfilingFunc() // to be executed as late as possible
159 }
160
161 - res, err := callCommand(ctx, i.req, Root)
161 + res, err := callCommand(ctx, i.req, Root, i.cmd)
162 if err != nil {
163 return nil, err
164 }
@@ -296,7 +296,7 @@ func callPreCommandHooks(ctx context.Context, details cmdDetails, req cmds.Reque
296 return nil
297 }
298
299 -func callCommand(ctx context.Context, req cmds.Request, root *cmds.Command) (cmds.Response, error) {
299 +func callCommand(ctx context.Context, req cmds.Request, root *cmds.Command, cmd *cmds.Command) (cmds.Response, error) {
300 var res cmds.Response
301
302 details, err := commandDetails(req.Path(), root)
@@ -347,6 +347,11 @@ func callCommand(ctx context.Context, req cmds.Request, root *cmds.Command) (cmd
347 res = root.Call(req)
348
349 }
350 +
351 + if cmd.PostRun != nil {
352 + cmd.PostRun(res)
353 + }
354 +
355 return res, nil
356 }
357
commands/command.go
+1
@@ -46,6 +46,7 @@ type Command struct {
46 Options []Option
47 Arguments []Argument
48 Run Function
49 + PostRun func(res Response)
50 Marshalers map[EncodingType]Marshaler
51 Helptext HelpText
52