mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-14 17:46:26 -04:00
Until now every keybinding config field was a plain string. That meant a user
couldn't ask for two keys to invoke a command — the config silently accepted
only one form.
Convert every string-typed field across all 13 KeybindingXxxConfig structs to
Keybinding so the union type extends to every command. Defaults wrap their
single-key value in Keybinding{...} so the generated Config.md still renders one
scalar key per binding.
The alt fields keep their separate Binding registrations for now: this commit
does not yet introduce the merge mechanism that folds them into the main field —
that comes in a follow-up. Consumers previously calling opts.GetKeys on a string
field now call opts.GetKeys on the Keybinding, or take .String() / Keys[0] where
a single value is needed.
Adds a Keybinding.String helper for rendering, schema-generator work that
inlines the Keybinding union into each consuming property, and a unit test
covering the user-facing scalar/sequence YAML forms for quit.
77 lines
1.9 KiB
Go
77 lines
1.9 KiB
Go
package demo
|
|
|
|
import (
|
|
"github.com/jesseduffield/lazygit/pkg/config"
|
|
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
|
)
|
|
|
|
var customCommandContent = `
|
|
customCommands:
|
|
- key: 'a'
|
|
command: 'git checkout {{.Form.Branch}}'
|
|
context: 'localBranches'
|
|
prompts:
|
|
- type: 'input'
|
|
title: 'Enter a branch name to checkout:'
|
|
key: 'Branch'
|
|
suggestions:
|
|
preset: 'branches'
|
|
`
|
|
|
|
var CustomCommand = NewIntegrationTest(NewIntegrationTestArgs{
|
|
Description: "Invoke a custom command",
|
|
ExtraCmdArgs: []string{},
|
|
Skip: false,
|
|
IsDemo: true,
|
|
SetupConfig: func(cfg *config.AppConfig) {
|
|
setDefaultDemoConfig(cfg)
|
|
|
|
cfg.GetUserConfig().CustomCommands = []config.CustomCommand{
|
|
{
|
|
Key: "a",
|
|
Context: "localBranches",
|
|
Command: `git checkout {{.Form.Branch}}`,
|
|
Prompts: []config.CustomCommandPrompt{
|
|
{
|
|
Key: "Branch",
|
|
Type: "input",
|
|
Title: "Enter a branch name to checkout",
|
|
Suggestions: config.CustomCommandSuggestions{
|
|
Preset: "branches",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
},
|
|
SetupRepo: func(shell *Shell) {
|
|
shell.CreateNCommitsWithRandomMessages(30)
|
|
shell.NewBranch("feature/user-authentication")
|
|
shell.NewBranch("feature/payment-processing")
|
|
shell.NewBranch("feature/search-functionality")
|
|
shell.NewBranch("feature/mobile-responsive")
|
|
shell.EmptyCommit("Make mobile response")
|
|
shell.NewBranch("bugfix/fix-login-issue")
|
|
shell.HardReset("HEAD~1")
|
|
shell.NewBranch("bugfix/fix-crash-bug")
|
|
shell.CreateFile("custom_commands_example.yml", customCommandContent)
|
|
},
|
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
|
t.SetCaptionPrefix("Invoke a custom command")
|
|
t.Wait(1500)
|
|
|
|
t.Views().Branches().
|
|
Focus().
|
|
Wait(500).
|
|
Press(config.Keybinding{"a"}).
|
|
Tap(func() {
|
|
t.Wait(500)
|
|
|
|
t.ExpectPopup().Prompt().
|
|
Title(Equals("Enter a branch name to checkout")).
|
|
Type("mobile").
|
|
ConfirmFirstSuggestion()
|
|
})
|
|
},
|
|
})
|