From 1281b251058fdfce67e105efe0b02f63a2a854ce Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Tue, 20 Jan 2015 19:03:37 -0800 Subject: [PATCH] commands: Added PostRun function, called on the client --- cmd/ipfs/main.go | 9 +++++++-- commands/command.go | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cmd/ipfs/main.go b/cmd/ipfs/main.go index 96f680bcb..17d773ab2 100644 --- a/cmd/ipfs/main.go +++ b/cmd/ipfs/main.go @@ -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 } diff --git a/commands/command.go b/commands/command.go index 577e2649e..74beeec6e 100644 --- a/commands/command.go +++ b/commands/command.go @@ -46,6 +46,7 @@ type Command struct { Options []Option Arguments []Argument Run Function + PostRun func(res Response) Marshalers map[EncodingType]Marshaler Helptext HelpText