mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-12 12:55:47 +02:00
no more mocking command
This commit is contained in:
parent
25195eacee
commit
2cb8aff940
3 changed files with 5 additions and 21 deletions
|
@ -2,9 +2,9 @@ package oscommands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/secureexec"
|
||||||
"github.com/mgutz/str"
|
"github.com/mgutz/str"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -22,10 +22,7 @@ type ICmdObjBuilder interface {
|
||||||
type CmdObjBuilder struct {
|
type CmdObjBuilder struct {
|
||||||
runner ICmdObjRunner
|
runner ICmdObjRunner
|
||||||
logCmdObj func(ICmdObj)
|
logCmdObj func(ICmdObj)
|
||||||
// TODO: see if you can just remove this entirely and use secureexec.Command,
|
platform *Platform
|
||||||
// now that we're mocking out the runner itself.
|
|
||||||
command func(string, ...string) *exec.Cmd
|
|
||||||
platform *Platform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// poor man's version of explicitly saying that struct X implements interface Y
|
// 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 {
|
func (self *CmdObjBuilder) New(cmdStr string) ICmdObj {
|
||||||
args := str.ToArgv(cmdStr)
|
args := str.ToArgv(cmdStr)
|
||||||
cmd := self.command(args[0], args[1:]...)
|
cmd := secureexec.Command(args[0], args[1:]...)
|
||||||
cmd.Env = os.Environ()
|
cmd.Env = os.Environ()
|
||||||
|
|
||||||
return &CmdObj{
|
return &CmdObj{
|
||||||
|
@ -45,7 +42,7 @@ func (self *CmdObjBuilder) New(cmdStr string) ICmdObj {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *CmdObjBuilder) NewFromArgs(args []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()
|
cmd.Env = os.Environ()
|
||||||
|
|
||||||
return &CmdObj{
|
return &CmdObj{
|
||||||
|
@ -66,7 +63,6 @@ func (self *CmdObjBuilder) CloneWithNewRunner(decorate func(ICmdObjRunner) ICmdO
|
||||||
return &CmdObjBuilder{
|
return &CmdObjBuilder{
|
||||||
runner: decoratedRunner,
|
runner: decoratedRunner,
|
||||||
logCmdObj: self.logCmdObj,
|
logCmdObj: self.logCmdObj,
|
||||||
command: self.command,
|
|
||||||
platform: self.platform,
|
platform: self.platform,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package oscommands
|
package oscommands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/jesseduffield/lazygit/pkg/secureexec"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -14,7 +13,6 @@ func NewDummyCmdObjBuilder(runner ICmdObjRunner) *CmdObjBuilder {
|
||||||
return &CmdObjBuilder{
|
return &CmdObjBuilder{
|
||||||
runner: runner,
|
runner: runner,
|
||||||
logCmdObj: func(ICmdObj) {},
|
logCmdObj: func(ICmdObj) {},
|
||||||
command: secureexec.Command,
|
|
||||||
platform: &Platform{
|
platform: &Platform{
|
||||||
OS: "darwin",
|
OS: "darwin",
|
||||||
Shell: "bash",
|
Shell: "bash",
|
||||||
|
|
|
@ -13,7 +13,6 @@ import (
|
||||||
|
|
||||||
"github.com/atotto/clipboard"
|
"github.com/atotto/clipboard"
|
||||||
"github.com/jesseduffield/lazygit/pkg/common"
|
"github.com/jesseduffield/lazygit/pkg/common"
|
||||||
"github.com/jesseduffield/lazygit/pkg/secureexec"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,7 +20,6 @@ import (
|
||||||
type OSCommand struct {
|
type OSCommand struct {
|
||||||
*common.Common
|
*common.Common
|
||||||
Platform *Platform
|
Platform *Platform
|
||||||
Command func(string, ...string) *exec.Cmd
|
|
||||||
Getenv func(string) string
|
Getenv func(string) string
|
||||||
|
|
||||||
// callback to run before running a command, i.e. for the purposes of logging
|
// 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
|
// NewOSCommand os command runner
|
||||||
func NewOSCommand(common *common.Common) *OSCommand {
|
func NewOSCommand(common *common.Common) *OSCommand {
|
||||||
command := secureexec.Command
|
|
||||||
platform := getPlatform()
|
platform := getPlatform()
|
||||||
|
|
||||||
c := &OSCommand{
|
c := &OSCommand{
|
||||||
Common: common,
|
Common: common,
|
||||||
Platform: platform,
|
Platform: platform,
|
||||||
Command: command,
|
|
||||||
Getenv: os.Getenv,
|
Getenv: os.Getenv,
|
||||||
removeFile: os.RemoveAll,
|
removeFile: os.RemoveAll,
|
||||||
}
|
}
|
||||||
|
|
||||||
runner := &cmdObjRunner{log: common.Log, logCmdObj: c.LogCmdObj}
|
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
|
return c
|
||||||
}
|
}
|
||||||
|
@ -125,12 +121,6 @@ func (c *OSCommand) SetOnRunCommand(f func(CmdLogEntry)) {
|
||||||
c.onRunCommand = f
|
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
|
// To be used for testing only
|
||||||
func (c *OSCommand) SetRemoveFile(f func(string) error) {
|
func (c *OSCommand) SetRemoveFile(f func(string) error) {
|
||||||
c.removeFile = f
|
c.removeFile = f
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue