mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-13 22:17:05 +02:00
refactor
This commit is contained in:
parent
f503ff1ecb
commit
007235df23
@ -21,11 +21,8 @@ func NewDummyGitCommandWithOSCommand(osCommand *oscommands.OSCommand) *GitComman
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDummyGitCommandWithRunner(runner oscommands.ICmdObjRunner) *GitCommand {
|
func NewDummyGitCommandWithRunner(runner *oscommands.FakeCmdObjRunner) *GitCommand {
|
||||||
builder := oscommands.NewDummyCmdObjBuilder(runner)
|
osCommand := oscommands.NewDummyOSCommandWithRunner(runner)
|
||||||
gitCommand := NewDummyGitCommand()
|
|
||||||
gitCommand.Cmd = builder
|
|
||||||
gitCommand.OSCommand.Cmd = builder
|
|
||||||
|
|
||||||
return gitCommand
|
return NewDummyGitCommandWithOSCommand(osCommand)
|
||||||
}
|
}
|
||||||
|
@ -92,6 +92,10 @@ func NewGitCommandAux(
|
|||||||
) *GitCommand {
|
) *GitCommand {
|
||||||
cmd := NewGitCmdObjBuilder(cmn.Log, osCommand.Cmd)
|
cmd := NewGitCmdObjBuilder(cmn.Log, osCommand.Cmd)
|
||||||
|
|
||||||
|
// here we're doing a bunch of dependency injection for each of our commands structs.
|
||||||
|
// This is admittedly messy, but allows us to test each command struct in isolation,
|
||||||
|
// and allows for better namespacing when compared to having every method living
|
||||||
|
// on the one struct.
|
||||||
configCommands := NewConfigCommands(cmn, gitConfig)
|
configCommands := NewConfigCommands(cmn, gitConfig)
|
||||||
statusCommands := NewStatusCommands(cmn, osCommand, repo, dotGitDir)
|
statusCommands := NewStatusCommands(cmn, osCommand, repo, dotGitDir)
|
||||||
fileLoader := loaders.NewFileLoader(cmn, cmd, configCommands)
|
fileLoader := loaders.NewFileLoader(cmn, cmd, configCommands)
|
||||||
|
@ -21,12 +21,7 @@ type OSCommand struct {
|
|||||||
*common.Common
|
*common.Common
|
||||||
Platform *Platform
|
Platform *Platform
|
||||||
GetenvFn func(string) string
|
GetenvFn func(string) string
|
||||||
|
guiIO *guiIO
|
||||||
// callback to run before running a command, i.e. for the purposes of logging.
|
|
||||||
// the string argument is the command string e.g. 'git add .' and the bool is
|
|
||||||
// whether we're dealing with a command line command or something more general
|
|
||||||
// like 'Opening PR URL', or something handled by Go's standard library.
|
|
||||||
logCommandFn func(string, bool)
|
|
||||||
|
|
||||||
removeFile func(string) error
|
removeFile func(string) error
|
||||||
|
|
||||||
@ -49,6 +44,7 @@ func NewOSCommand(common *common.Common, platform *Platform, guiIO *guiIO) *OSCo
|
|||||||
Platform: platform,
|
Platform: platform,
|
||||||
GetenvFn: os.Getenv,
|
GetenvFn: os.Getenv,
|
||||||
removeFile: os.RemoveAll,
|
removeFile: os.RemoveAll,
|
||||||
|
guiIO: guiIO,
|
||||||
}
|
}
|
||||||
|
|
||||||
runner := &cmdObjRunner{log: common.Log, guiIO: guiIO}
|
runner := &cmdObjRunner{log: common.Log, guiIO: guiIO}
|
||||||
@ -60,13 +56,7 @@ func NewOSCommand(common *common.Common, platform *Platform, guiIO *guiIO) *OSCo
|
|||||||
func (c *OSCommand) LogCommand(cmdStr string, commandLine bool) {
|
func (c *OSCommand) LogCommand(cmdStr string, commandLine bool) {
|
||||||
c.Log.WithField("command", cmdStr).Info("RunCommand")
|
c.Log.WithField("command", cmdStr).Info("RunCommand")
|
||||||
|
|
||||||
if c.logCommandFn != nil {
|
c.guiIO.logCommandFn(cmdStr, commandLine)
|
||||||
c.logCommandFn(cmdStr, commandLine)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *OSCommand) SetLogCommandFn(f func(string, bool)) {
|
|
||||||
c.logCommandFn = f
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// To be used for testing only
|
// To be used for testing only
|
||||||
|
Loading…
x
Reference in New Issue
Block a user