From 856d2896a7dce5d509f8438b81677a218a8125bb Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Wed, 21 Jan 2015 15:18:45 -0800 Subject: [PATCH] commands: Added PreRun function to command --- cmd/ipfs/main.go | 7 +++++++ commands/command.go | 1 + 2 files changed, 8 insertions(+) diff --git a/cmd/ipfs/main.go b/cmd/ipfs/main.go index 17d773ab2..e50a5ca16 100644 --- a/cmd/ipfs/main.go +++ b/cmd/ipfs/main.go @@ -315,6 +315,13 @@ func callCommand(ctx context.Context, req cmds.Request, root *cmds.Command, cmd return nil, err } + if cmd.PreRun != nil { + err = cmd.PreRun(req) + if err != nil { + return nil, err + } + } + if useDaemon { cfg, err := req.Context().GetConfig() diff --git a/commands/command.go b/commands/command.go index 74beeec6e..f79bf31c0 100644 --- a/commands/command.go +++ b/commands/command.go @@ -45,6 +45,7 @@ type HelpText struct { type Command struct { Options []Option Arguments []Argument + PreRun func(req Request) error Run Function PostRun func(res Response) Marshalers map[EncodingType]Marshaler