commands: Added PostRun function, called on the client

This commit is contained in:
Matt Bell 2015-01-20 19:03:37 -08:00
parent 7294f6334a
commit 1281b25105
2 changed files with 8 additions and 2 deletions

View File

@ -158,7 +158,7 @@ func (i *cmdInvocation) Run(ctx context.Context) (output io.Reader, err error) {
defer stopProfilingFunc() // to be executed as late as possible
}
res, err := callCommand(ctx, i.req, Root)
res, err := callCommand(ctx, i.req, Root, i.cmd)
if err != nil {
return nil, err
}
@ -296,7 +296,7 @@ func callPreCommandHooks(ctx context.Context, details cmdDetails, req cmds.Reque
return nil
}
func callCommand(ctx context.Context, req cmds.Request, root *cmds.Command) (cmds.Response, error) {
func callCommand(ctx context.Context, req cmds.Request, root *cmds.Command, cmd *cmds.Command) (cmds.Response, error) {
var res cmds.Response
details, err := commandDetails(req.Path(), root)
@ -347,6 +347,11 @@ func callCommand(ctx context.Context, req cmds.Request, root *cmds.Command) (cmd
res = root.Call(req)
}
if cmd.PostRun != nil {
cmd.PostRun(res)
}
return res, nil
}

View File

@ -46,6 +46,7 @@ type Command struct {
Options []Option
Arguments []Argument
Run Function
PostRun func(res Response)
Marshalers map[EncodingType]Marshaler
Helptext HelpText