summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2022-01-07 14:45:18 +1100
committerJesse Duffield <jessedduffield@gmail.com>2022-01-09 14:09:53 +1100
commit007235df2355bfeacc206b78e9827fff529d32a2 (patch)
tree3cb89ef2816119170dd69e126ace2d1bff446a2e
parentf503ff1ecbfda00dfa4e68e38d41aceaf9b4400c (diff)
refactor
-rw-r--r--pkg/commands/dummies.go9
-rw-r--r--pkg/commands/git.go4
-rw-r--r--pkg/commands/oscommands/os.go16
3 files changed, 10 insertions, 19 deletions
diff --git a/pkg/commands/dummies.go b/pkg/commands/dummies.go
index 1f4b4c1ef..38982b93a 100644
--- a/pkg/commands/dummies.go
+++ b/pkg/commands/dummies.go
@@ -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)
}
diff --git a/pkg/commands/git.go b/pkg/commands/git.go
index 4866655e0..2f4c68fb8 100644
--- a/pkg/commands/git.go
+++ b/pkg/commands/git.go
@@ -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)
diff --git a/pkg/commands/oscommands/os.go b/pkg/commands/oscommands/os.go
index a66dfb366..f8ad29c1f 100644
--- a/pkg/commands/oscommands/os.go
+++ b/pkg/commands/oscommands/os.go
@@ -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