Skip to content

Commit 4e3d09e

Browse files
committed
Validate custom commands in sub menus
1 parent e295477 commit 4e3d09e

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

pkg/config/user_config_validation.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,26 @@ func validateCustomCommands(customCommands []CustomCommand) error {
101101
return err
102102
}
103103

104-
if len(customCommand.CommandMenu) > 0 &&
105-
(len(customCommand.Context) > 0 ||
104+
if len(customCommand.CommandMenu) > 0 {
105+
if len(customCommand.Context) > 0 ||
106106
len(customCommand.Command) > 0 ||
107107
customCommand.Subprocess != nil ||
108108
len(customCommand.Prompts) > 0 ||
109109
len(customCommand.LoadingText) > 0 ||
110110
customCommand.Stream != nil ||
111111
customCommand.ShowOutput != nil ||
112112
len(customCommand.OutputTitle) > 0 ||
113-
customCommand.After != nil) {
114-
commandRef := ""
115-
if len(customCommand.Key) > 0 {
116-
commandRef = fmt.Sprintf(" with key '%s'", customCommand.Key)
113+
customCommand.After != nil {
114+
commandRef := ""
115+
if len(customCommand.Key) > 0 {
116+
commandRef = fmt.Sprintf(" with key '%s'", customCommand.Key)
117+
}
118+
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)
119+
}
120+
121+
if err := validateCustomCommands(customCommand.CommandMenu); err != nil {
122+
return err
117123
}
118-
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)
119124
}
120125
}
121126
return nil

pkg/config/user_config_validation_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,7 @@ func TestUserConfigValidate_enums(t *testing.T) {
9292
{value: "<disabled>", valid: true},
9393
{value: "q", valid: true},
9494
{value: "<c-c>", valid: true},
95-
/* EXPECTED:
9695
{value: "invalid_value", valid: false},
97-
ACTUAL */
98-
{value: "invalid_value", valid: true},
9996
},
10097
},
10198
{

0 commit comments

Comments
 (0)