mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-31 14:24:25 +03:00
Validate properties of customCommand when commandMenu is used
This commit is contained in:
@ -96,6 +96,23 @@ func validateCustomCommands(customCommands []CustomCommand) error {
|
|||||||
if err := validateCustomCommandKey(customCommand.Key); err != nil {
|
if err := validateCustomCommandKey(customCommand.Key); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(customCommand.CommandMenu) > 0 &&
|
||||||
|
(len(customCommand.Context) > 0 ||
|
||||||
|
len(customCommand.Command) > 0 ||
|
||||||
|
customCommand.Subprocess != nil ||
|
||||||
|
len(customCommand.Prompts) > 0 ||
|
||||||
|
len(customCommand.LoadingText) > 0 ||
|
||||||
|
customCommand.Stream != nil ||
|
||||||
|
customCommand.ShowOutput != nil ||
|
||||||
|
len(customCommand.OutputTitle) > 0 ||
|
||||||
|
customCommand.After != nil) {
|
||||||
|
commandRef := ""
|
||||||
|
if len(customCommand.Key) > 0 {
|
||||||
|
commandRef = fmt.Sprintf(" with key '%s'", customCommand.Key)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("Error with custom command%s: it is not allowed to use both commandMenu and any of the other fields except key and description.", commandRef)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -74,6 +74,58 @@ func TestUserConfigValidate_enums(t *testing.T) {
|
|||||||
{value: "invalid_value", valid: false},
|
{value: "invalid_value", valid: false},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Custom command sub menu",
|
||||||
|
setup: func(config *UserConfig, _ string) {
|
||||||
|
config.CustomCommands = []CustomCommand{
|
||||||
|
{
|
||||||
|
Key: "X",
|
||||||
|
Description: "My Custom Commands",
|
||||||
|
CommandMenu: []CustomCommand{
|
||||||
|
{Key: "1", Command: "echo 'hello'", Context: "global"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
testCases: []testCase{
|
||||||
|
{value: "", valid: true},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Custom command sub menu",
|
||||||
|
setup: func(config *UserConfig, _ string) {
|
||||||
|
config.CustomCommands = []CustomCommand{
|
||||||
|
{
|
||||||
|
Key: "X",
|
||||||
|
Context: "global",
|
||||||
|
CommandMenu: []CustomCommand{
|
||||||
|
{Key: "1", Command: "echo 'hello'", Context: "global"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
testCases: []testCase{
|
||||||
|
{value: "", valid: false},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Custom command sub menu",
|
||||||
|
setup: func(config *UserConfig, _ string) {
|
||||||
|
falseVal := false
|
||||||
|
config.CustomCommands = []CustomCommand{
|
||||||
|
{
|
||||||
|
Key: "X",
|
||||||
|
Subprocess: &falseVal,
|
||||||
|
CommandMenu: []CustomCommand{
|
||||||
|
{Key: "1", Command: "echo 'hello'", Context: "global"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
testCases: []testCase{
|
||||||
|
{value: "", valid: false},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
|
Reference in New Issue
Block a user