diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-12-31 10:46:34 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2022-01-04 09:07:15 +1100 |
commit | 2cb8aff940b79f20a09c0ed2bde13ec3b34a13cb (patch) | |
tree | 2f8bae9adaaddbed04d7e4d7bc5025deca4e8156 /pkg | |
parent | 25195eacee01a25f53a5606623a9e74aa9d98982 (diff) |
no more mocking command
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/commands/oscommands/cmd_obj_builder.go | 12 | ||||
-rw-r--r-- | pkg/commands/oscommands/dummies.go | 2 | ||||
-rw-r--r-- | pkg/commands/oscommands/os.go | 12 |
3 files changed, 5 insertions, 21 deletions
diff --git a/pkg/commands/oscommands/cmd_obj_builder.go b/pkg/commands/oscommands/cmd_obj_builder.go index 84a3f9e09..85e28f566 100644 --- a/pkg/commands/oscommands/cmd_obj_builder.go +++ b/pkg/commands/oscommands/cmd_obj_builder.go @@ -2,9 +2,9 @@ package oscommands import ( "os" - "os/exec" "strings" + "github.com/jesseduffield/lazygit/pkg/secureexec" "github.com/mgutz/str" ) @@ -22,10 +22,7 @@ type ICmdObjBuilder interface { type CmdObjBuilder struct { runner ICmdObjRunner logCmdObj func(ICmdObj) - // TODO: see if you can just remove this entirely and use secureexec.Command, - // now that we're mocking out the runner itself. - command func(string, ...string) *exec.Cmd - platform *Platform + platform *Platform } // poor man's version of explicitly saying that struct X implements interface Y @@ -33,7 +30,7 @@ var _ ICmdObjBuilder = &CmdObjBuilder{} func (self *CmdObjBuilder) New(cmdStr string) ICmdObj { args := str.ToArgv(cmdStr) - cmd := self.command(args[0], args[1:]...) + cmd := secureexec.Command(args[0], args[1:]...) cmd.Env = os.Environ() return &CmdObj{ @@ -45,7 +42,7 @@ func (self *CmdObjBuilder) New(cmdStr string) ICmdObj { } func (self *CmdObjBuilder) NewFromArgs(args []string) ICmdObj { - cmd := self.command(args[0], args[1:]...) + cmd := secureexec.Command(args[0], args[1:]...) cmd.Env = os.Environ() return &CmdObj{ @@ -66,7 +63,6 @@ func (self *CmdObjBuilder) CloneWithNewRunner(decorate func(ICmdObjRunner) ICmdO return &CmdObjBuilder{ runner: decoratedRunner, logCmdObj: self.logCmdObj, - command: self.command, platform: self.platform, } } diff --git a/pkg/commands/oscommands/dummies.go b/pkg/commands/oscommands/dummies.go index 34d23a399..d77993e62 100644 --- a/pkg/commands/oscommands/dummies.go +++ b/pkg/commands/oscommands/dummies.go @@ -1,7 +1,6 @@ package oscommands import ( - "github.com/jesseduffield/lazygit/pkg/secureexec" "github.com/jesseduffield/lazygit/pkg/utils" ) @@ -14,7 +13,6 @@ func NewDummyCmdObjBuilder(runner ICmdObjRunner) *CmdObjBuilder { return &CmdObjBuilder{ runner: runner, logCmdObj: func(ICmdObj) {}, - command: secureexec.Command, platform: &Platform{ OS: "darwin", Shell: "bash", diff --git a/pkg/commands/oscommands/os.go b/pkg/commands/oscommands/os.go index 9695472ae..5a7c5e0bb 100644 --- a/pkg/commands/oscommands/os.go +++ b/pkg/commands/oscommands/os.go @@ -13,7 +13,6 @@ import ( "github.com/atotto/clipboard" "github.com/jesseduffield/lazygit/pkg/common" - "github.com/jesseduffield/lazygit/pkg/secureexec" "github.com/jesseduffield/lazygit/pkg/utils" ) @@ -21,7 +20,6 @@ import ( type OSCommand struct { *common.Common Platform *Platform - Command func(string, ...string) *exec.Cmd Getenv func(string) string // callback to run before running a command, i.e. for the purposes of logging @@ -76,19 +74,17 @@ func NewCmdLogEntry(cmdStr string, span string, commandLine bool) CmdLogEntry { // NewOSCommand os command runner func NewOSCommand(common *common.Common) *OSCommand { - command := secureexec.Command platform := getPlatform() c := &OSCommand{ Common: common, Platform: platform, - Command: command, Getenv: os.Getenv, removeFile: os.RemoveAll, } runner := &cmdObjRunner{log: common.Log, logCmdObj: c.LogCmdObj} - c.Cmd = &CmdObjBuilder{runner: runner, command: command, logCmdObj: c.LogCmdObj, platform: platform} + c.Cmd = &CmdObjBuilder{runner: runner, logCmdObj: c.LogCmdObj, platform: platform} return c } @@ -125,12 +121,6 @@ func (c *OSCommand) SetOnRunCommand(f func(CmdLogEntry)) { 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) { - c.Command = cmd -} - // To be used for testing only func (c *OSCommand) SetRemoveFile(f func(string) error) { c.removeFile = f |