summaryrefslogtreecommitdiffstats
path: root/pkg/gui/services/custom_commands
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-03-23 18:47:29 +1100
committerJesse Duffield <jessedduffield@gmail.com>2023-04-30 13:19:53 +1000
commitdb12853bbe825d69686ea71161497d1bbb120b8e (patch)
treeebfb066dfef8eb75acdc1ea2bd5f15ff4f4a6507 /pkg/gui/services/custom_commands
parent711674f6cd68ed3a35e5b0329ff0cf3289fbc7d1 (diff)
lots of changes
Diffstat (limited to 'pkg/gui/services/custom_commands')
-rw-r--r--pkg/gui/services/custom_commands/client.go12
-rw-r--r--pkg/gui/services/custom_commands/handler_creator.go14
-rw-r--r--pkg/gui/services/custom_commands/keybinding_creator.go9
-rw-r--r--pkg/gui/services/custom_commands/session_state_loader.go38
4 files changed, 30 insertions, 43 deletions
diff --git a/pkg/gui/services/custom_commands/client.go b/pkg/gui/services/custom_commands/client.go
index 4db916a66..4cacba385 100644
--- a/pkg/gui/services/custom_commands/client.go
+++ b/pkg/gui/services/custom_commands/client.go
@@ -1,10 +1,7 @@
package custom_commands
import (
- "github.com/jesseduffield/lazygit/pkg/commands"
- "github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/config"
- "github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@@ -19,14 +16,11 @@ type Client struct {
func NewClient(
c *helpers.HelperCommon,
- os *oscommands.OSCommand,
- git *commands.GitCommand,
- contexts *context.ContextTree,
helpers *helpers.Helpers,
) *Client {
- sessionStateLoader := NewSessionStateLoader(contexts, helpers)
- handlerCreator := NewHandlerCreator(c, os, git, sessionStateLoader)
- keybindingCreator := NewKeybindingCreator(contexts)
+ sessionStateLoader := NewSessionStateLoader(c, helpers.Refs)
+ handlerCreator := NewHandlerCreator(c, sessionStateLoader)
+ keybindingCreator := NewKeybindingCreator(c)
customCommands := c.UserConfig.CustomCommands
return &Client{
diff --git a/pkg/gui/services/custom_commands/handler_creator.go b/pkg/gui/services/custom_commands/handler_creator.go
index 2772d0c1a..6ec005a37 100644
--- a/pkg/gui/services/custom_commands/handler_creator.go
+++ b/pkg/gui/services/custom_commands/handler_creator.go
@@ -5,8 +5,6 @@ import (
"text/template"
"github.com/jesseduffield/generics/slices"
- "github.com/jesseduffield/lazygit/pkg/commands"
- "github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
"github.com/jesseduffield/lazygit/pkg/gui/style"
@@ -17,8 +15,6 @@ import (
// takes a custom command and returns a function that will be called when the corresponding user-defined keybinding is pressed
type HandlerCreator struct {
c *helpers.HelperCommon
- os *oscommands.OSCommand
- git *commands.GitCommand
sessionStateLoader *SessionStateLoader
resolver *Resolver
menuGenerator *MenuGenerator
@@ -26,8 +22,6 @@ type HandlerCreator struct {
func NewHandlerCreator(
c *helpers.HelperCommon,
- os *oscommands.OSCommand,
- git *commands.GitCommand,
sessionStateLoader *SessionStateLoader,
) *HandlerCreator {
resolver := NewResolver(c.Common)
@@ -35,8 +29,6 @@ func NewHandlerCreator(
return &HandlerCreator{
c: c,
- os: os,
- git: git,
sessionStateLoader: sessionStateLoader,
resolver: resolver,
menuGenerator: menuGenerator,
@@ -144,7 +136,7 @@ func (self *HandlerCreator) confirmPrompt(prompt *config.CustomCommandPrompt, ha
func (self *HandlerCreator) menuPromptFromCommand(prompt *config.CustomCommandPrompt, wrappedF func(string) error) error {
// Run and save output
- message, err := self.git.Custom.RunWithOutput(prompt.Command)
+ message, err := self.c.Git().Custom.RunWithOutput(prompt.Command)
if err != nil {
return self.c.Error(err)
}
@@ -181,7 +173,7 @@ func (self *HandlerCreator) getResolveTemplateFn(form map[string]string, promptR
}
funcs := template.FuncMap{
- "quote": self.os.Quote,
+ "quote": self.c.OS().Quote,
}
return func(templateStr string) (string, error) { return utils.ResolveTemplate(templateStr, objects, funcs) }
@@ -194,7 +186,7 @@ func (self *HandlerCreator) finalHandler(customCommand config.CustomCommand, ses
return self.c.Error(err)
}
- cmdObj := self.os.Cmd.NewShell(cmdStr)
+ cmdObj := self.c.OS().Cmd.NewShell(cmdStr)
if customCommand.Subprocess {
return self.c.RunSubprocessAndRefresh(cmdObj)
diff --git a/pkg/gui/services/custom_commands/keybinding_creator.go b/pkg/gui/services/custom_commands/keybinding_creator.go
index 7251225fe..2482f03f2 100644
--- a/pkg/gui/services/custom_commands/keybinding_creator.go
+++ b/pkg/gui/services/custom_commands/keybinding_creator.go
@@ -8,18 +8,19 @@ import (
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/gui/context"
+ "github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
// KeybindingCreator takes a custom command along with its handler and returns a corresponding keybinding
type KeybindingCreator struct {
- contexts *context.ContextTree
+ c *helpers.HelperCommon
}
-func NewKeybindingCreator(contexts *context.ContextTree) *KeybindingCreator {
+func NewKeybindingCreator(c *helpers.HelperCommon) *KeybindingCreator {
return &KeybindingCreator{
- contexts: contexts,
+ c: c,
}
}
@@ -62,7 +63,7 @@ func (self *KeybindingCreator) getViewNameAndContexts(customCommand config.Custo
}
func (self *KeybindingCreator) contextForContextKey(contextKey types.ContextKey) (types.Context, bool) {
- for _, context := range self.contexts.Flatten() {
+ for _, context := range self.c.Contexts().Flatten() {
if context.GetKey() == contextKey {
return context, true
}
diff --git a/pkg/gui/services/custom_commands/session_state_loader.go b/pkg/gui/services/custom_commands/session_state_loader.go
index 42f3403ec..2ef7a44bd 100644
--- a/pkg/gui/services/custom_commands/session_state_loader.go
+++ b/pkg/gui/services/custom_commands/session_state_loader.go
@@ -2,21 +2,21 @@ package custom_commands
import (
"github.com/jesseduffield/lazygit/pkg/commands/models"
- "github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
)
// loads the session state at the time that a custom command is invoked, for use
// in the custom command's template strings
type SessionStateLoader struct {
- contexts *context.ContextTree
- helpers *helpers.Helpers
+ c *helpers.HelperCommon
+ helpers *helpers.Helpers
+ refsHelper *helpers.RefsHelper
}
-func NewSessionStateLoader(contexts *context.ContextTree, helpers *helpers.Helpers) *SessionStateLoader {
+func NewSessionStateLoader(c *helpers.HelperCommon, refsHelper *helpers.RefsHelper) *SessionStateLoader {
return &SessionStateLoader{
- contexts: contexts,
- helpers: helpers,
+ c: c,
+ refsHelper: refsHelper,
}
}
@@ -39,18 +39,18 @@ type SessionState struct {
func (self *SessionStateLoader) call() *SessionState {
return &SessionState{
- SelectedFile: self.contexts.Files.GetSelectedFile(),
- SelectedPath: self.contexts.Files.GetSelectedPath(),
- SelectedLocalCommit: self.contexts.LocalCommits.GetSelected(),
- SelectedReflogCommit: self.contexts.ReflogCommits.GetSelected(),
- SelectedLocalBranch: self.contexts.Branches.GetSelected(),
- SelectedRemoteBranch: self.contexts.RemoteBranches.GetSelected(),
- SelectedRemote: self.contexts.Remotes.GetSelected(),
- SelectedTag: self.contexts.Tags.GetSelected(),
- SelectedStashEntry: self.contexts.Stash.GetSelected(),
- SelectedCommitFile: self.contexts.CommitFiles.GetSelectedFile(),
- SelectedCommitFilePath: self.contexts.CommitFiles.GetSelectedPath(),
- SelectedSubCommit: self.contexts.SubCommits.GetSelected(),
- CheckedOutBranch: self.helpers.Refs.GetCheckedOutRef(),
+ SelectedFile: self.c.Contexts().Files.GetSelectedFile(),
+ SelectedPath: self.c.Contexts().Files.GetSelectedPath(),
+ SelectedLocalCommit: self.c.Contexts().LocalCommits.GetSelected(),
+ SelectedReflogCommit: self.c.Contexts().ReflogCommits.GetSelected(),
+ SelectedLocalBranch: self.c.Contexts().Branches.GetSelected(),
+ SelectedRemoteBranch: self.c.Contexts().RemoteBranches.GetSelected(),
+ SelectedRemote: self.c.Contexts().Remotes.GetSelected(),
+ SelectedTag: self.c.Contexts().Tags.GetSelected(),
+ SelectedStashEntry: self.c.Contexts().Stash.GetSelected(),
+ SelectedCommitFile: self.c.Contexts().CommitFiles.GetSelectedFile(),
+ SelectedCommitFilePath: self.c.Contexts().CommitFiles.GetSelectedPath(),
+ SelectedSubCommit: self.c.Contexts().SubCommits.GetSelected(),
+ CheckedOutBranch: self.refsHelper.GetCheckedOutRef(),
}
}