mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-31 14:24:25 +03:00
Validate keys of custom commands
This commit is contained in:
@ -22,6 +22,9 @@ func (config *UserConfig) Validate() error {
|
|||||||
if err := validateKeybindings(config.Keybinding); err != nil {
|
if err := validateKeybindings(config.Keybinding); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if err := validateCustomCommands(config.CustomCommands); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,3 +82,20 @@ func validateKeybindings(keybindingConfig KeybindingConfig) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func validateCustomCommandKey(key string) error {
|
||||||
|
if !isValidKeybindingKey(key) {
|
||||||
|
return fmt.Errorf("Unrecognized key '%s' for custom command. For permitted values see %s",
|
||||||
|
key, constants.Links.Docs.CustomKeybindings)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func validateCustomCommands(customCommands []CustomCommand) error {
|
||||||
|
for _, customCommand := range customCommands {
|
||||||
|
if err := validateCustomCommandKey(customCommand.Key); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -56,6 +56,24 @@ func TestUserConfigValidate_enums(t *testing.T) {
|
|||||||
{value: "1,2,3,4,5,6", valid: false},
|
{value: "1,2,3,4,5,6", valid: false},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Custom command keybinding",
|
||||||
|
setup: func(config *UserConfig, value string) {
|
||||||
|
config.CustomCommands = []CustomCommand{
|
||||||
|
{
|
||||||
|
Key: value,
|
||||||
|
Command: "echo 'hello'",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
testCases: []testCase{
|
||||||
|
{value: "", valid: true},
|
||||||
|
{value: "<disabled>", valid: true},
|
||||||
|
{value: "q", valid: true},
|
||||||
|
{value: "<c-c>", valid: true},
|
||||||
|
{value: "invalid_value", valid: false},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
|
Reference in New Issue
Block a user