diff options
-rw-r--r-- | pkg/commands/os.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/pkg/commands/os.go b/pkg/commands/os.go index 375a8e77e..e85b3e19c 100644 --- a/pkg/commands/os.go +++ b/pkg/commands/os.go @@ -36,6 +36,7 @@ type OSCommand struct { Platform *Platform Config config.AppConfigurer command func(string, ...string) *exec.Cmd + beforeExecuteCmd func(*exec.Cmd) getGlobalGitConfig func(string) (string, error) getenv func(string) string } @@ -47,6 +48,7 @@ func NewOSCommand(log *logrus.Entry, config config.AppConfigurer) *OSCommand { Platform: getPlatform(), Config: config, command: exec.Command, + beforeExecuteCmd: func(*exec.Cmd) {}, getGlobalGitConfig: gitconfig.Global, getenv: os.Getenv, } @@ -58,6 +60,10 @@ func (c *OSCommand) SetCommand(cmd func(string, ...string) *exec.Cmd) { c.command = cmd } +func (c *OSCommand) SetBeforeExecuteCmd(cmd func(*exec.Cmd)) { + c.beforeExecuteCmd = cmd +} + // RunCommandWithOutput wrapper around commands returning their output and error // NOTE: If you don't pass any formatArgs we'll just use the command directly, // however there's a bizarre compiler error/warning when you pass in a formatString @@ -76,6 +82,7 @@ func (c *OSCommand) RunCommandWithOutput(formatString string, formatArgs ...inte // RunExecutableWithOutput runs an executable file and returns its output func (c *OSCommand) RunExecutableWithOutput(cmd *exec.Cmd) (string, error) { + c.beforeExecuteCmd(cmd) return sanitisedCommandOutput(cmd.CombinedOutput()) } @@ -308,6 +315,7 @@ func (c *OSCommand) FileExists(path string) (bool, error) { // this is useful if you need to give your command some environment variables // before running it func (c *OSCommand) RunPreparedCommand(cmd *exec.Cmd) error { + c.beforeExecuteCmd(cmd) out, err := cmd.CombinedOutput() outString := string(out) c.Log.Info(outString) |