Validate custom commands in sub menus

This commit is contained in:
Stefan Haller 2025-04-30 17:37:06 +02:00
parent e295477951
commit 4e3d09e9d8
2 changed files with 12 additions and 10 deletions

View file

@ -101,8 +101,8 @@ func validateCustomCommands(customCommands []CustomCommand) error {
return err
}
if len(customCommand.CommandMenu) > 0 &&
(len(customCommand.Context) > 0 ||
if len(customCommand.CommandMenu) > 0 {
if len(customCommand.Context) > 0 ||
len(customCommand.Command) > 0 ||
customCommand.Subprocess != nil ||
len(customCommand.Prompts) > 0 ||
@ -110,12 +110,17 @@ func validateCustomCommands(customCommands []CustomCommand) error {
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)
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)
}
if err := validateCustomCommands(customCommand.CommandMenu); err != nil {
return err
}
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

View file

@ -92,10 +92,7 @@ func TestUserConfigValidate_enums(t *testing.T) {
{value: "<disabled>", valid: true},
{value: "q", valid: true},
{value: "<c-c>", valid: true},
/* EXPECTED:
{value: "invalid_value", valid: false},
ACTUAL */
{value: "invalid_value", valid: true},
},
},
{