1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-14 11:23:09 +02:00
lazygit/pkg/gui/services/custom_commands/client.go

46 lines
1.4 KiB
Go
Raw Normal View History

package custom_commands
import (
"github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
2022-04-03 22:19:15 +02:00
// Client is the entry point to this package. It returns a list of keybindings based on the config's user-defined custom commands.
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Custom_Command_Keybindings.md for more info.
type Client struct {
customCommands []config.CustomCommand
handlerCreator *HandlerCreator
keybindingCreator *KeybindingCreator
}
func NewClient(
c *helpers.HelperCommon,
helpers *helpers.Helpers,
) *Client {
2023-03-23 09:47:29 +02:00
sessionStateLoader := NewSessionStateLoader(c, helpers.Refs)
handlerCreator := NewHandlerCreator(c, sessionStateLoader, helpers.Suggestions)
2023-03-23 09:47:29 +02:00
keybindingCreator := NewKeybindingCreator(c)
customCommands := c.UserConfig.CustomCommands
return &Client{
customCommands: customCommands,
keybindingCreator: keybindingCreator,
handlerCreator: handlerCreator,
}
}
func (self *Client) GetCustomCommandKeybindings() ([]*types.Binding, error) {
bindings := []*types.Binding{}
for _, customCommand := range self.customCommands {
handler := self.handlerCreator.call(customCommand)
binding, err := self.keybindingCreator.call(customCommand, handler)
if err != nil {
return nil, err
}
bindings = append(bindings, binding)
}
return bindings, nil
}