diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-04-10 13:08:51 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-04-11 17:07:49 +1000 |
commit | e145090046e1693e2100cb0a0ab40a271705f4b0 (patch) | |
tree | cad1068b2916e0864eb619e28330c46fd62e48fd /pkg/commands/oscommands | |
parent | 70b5c822bb2dfc3b82e8fa7a97fab0bff0c4960b (diff) |
add cmdLog panel
Diffstat (limited to 'pkg/commands/oscommands')
-rw-r--r-- | pkg/commands/oscommands/os.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/pkg/commands/oscommands/os.go b/pkg/commands/oscommands/os.go index 1a486162f..5b9b4dd91 100644 --- a/pkg/commands/oscommands/os.go +++ b/pkg/commands/oscommands/os.go @@ -40,6 +40,7 @@ type OSCommand struct { Command func(string, ...string) *exec.Cmd BeforeExecuteCmd func(*exec.Cmd) Getenv func(string) string + onRunCommand func(string) } // NewOSCommand os command runner @@ -54,6 +55,10 @@ func NewOSCommand(log *logrus.Entry, config config.AppConfigurer) *OSCommand { } } +func (c *OSCommand) SetOnRunCommand(f func(string)) { + c.onRunCommand = f +} + // SetCommand sets the command function used by the struct. // To be used for testing only func (c *OSCommand) SetCommand(cmd func(string, ...string) *exec.Cmd) { @@ -70,6 +75,9 @@ type RunCommandOptions struct { func (c *OSCommand) RunCommandWithOutputWithOptions(command string, options RunCommandOptions) (string, error) { c.Log.WithField("command", command).Info("RunCommand") + if c.onRunCommand != nil { + c.onRunCommand(command) + } cmd := c.ExecutableFromString(command) cmd.Env = append(cmd.Env, "GIT_TERMINAL_PROMPT=0") // prevents git from prompting us for input which would freeze the program @@ -95,6 +103,9 @@ func (c *OSCommand) RunCommandWithOutput(formatString string, formatArgs ...inte command = fmt.Sprintf(formatString, formatArgs...) } c.Log.WithField("command", command).Info("RunCommand") + if c.onRunCommand != nil { + c.onRunCommand(command) + } cmd := c.ExecutableFromString(command) output, err := sanitisedCommandOutput(cmd.CombinedOutput()) if err != nil { |