mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-01-06 03:53:59 +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 {
|
||||
builder := oscommands.NewDummyCmdObjBuilder(runner)
|
||||
gitCommand := NewDummyGitCommand()
|
||||
gitCommand.Cmd = builder
|
||||
gitCommand.OSCommand.Cmd = builder
|
||||
func NewDummyGitCommandWithRunner(runner *oscommands.FakeCmdObjRunner) *GitCommand {
|
||||
osCommand := oscommands.NewDummyOSCommandWithRunner(runner)
|
||||
|
||||
return gitCommand
|
||||
return NewDummyGitCommandWithOSCommand(osCommand)
|
||||
}
|
||||
|
@ -92,6 +92,10 @@ func NewGitCommandAux(
|
||||
) *GitCommand {
|
||||
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)
|
||||
statusCommands := NewStatusCommands(cmn, osCommand, repo, dotGitDir)
|
||||
fileLoader := loaders.NewFileLoader(cmn, cmd, configCommands)
|
||||
|
@ -21,12 +21,7 @@ type OSCommand struct {
|
||||
*common.Common
|
||||
Platform *Platform
|
||||
GetenvFn func(string) string
|
||||
|
||||
// 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)
|
||||
guiIO *guiIO
|
||||
|
||||
removeFile func(string) error
|
||||
|
||||
@ -49,6 +44,7 @@ func NewOSCommand(common *common.Common, platform *Platform, guiIO *guiIO) *OSCo
|
||||
Platform: platform,
|
||||
GetenvFn: os.Getenv,
|
||||
removeFile: os.RemoveAll,
|
||||
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) {
|
||||
c.Log.WithField("command", cmdStr).Info("RunCommand")
|
||||
|
||||
if c.logCommandFn != nil {
|
||||
c.logCommandFn(cmdStr, commandLine)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *OSCommand) SetLogCommandFn(f func(string, bool)) {
|
||||
c.logCommandFn = f
|
||||
c.guiIO.logCommandFn(cmdStr, commandLine)
|
||||
}
|
||||
|
||||
// To be used for testing only
|
||||
|
Loading…
Reference in New Issue
Block a user