1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-27 12:32:37 +02:00

no more mocking command

This commit is contained in:
Jesse Duffield 2021-12-31 10:46:34 +11:00
parent 25195eacee
commit 2cb8aff940
3 changed files with 5 additions and 21 deletions

View File

@ -2,9 +2,9 @@ package oscommands
import (
"os"
"os/exec"
"strings"
"github.com/jesseduffield/lazygit/pkg/secureexec"
"github.com/mgutz/str"
)
@ -22,9 +22,6 @@ 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
}
@ -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,
}
}

View File

@ -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",

View File

@ -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