diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-09-27 09:37:22 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-09-27 09:49:30 +1000 |
commit | a09bb5d4d83c9738969b337d82e14e4bbe34dd53 (patch) | |
tree | 2bf51c23618ef52d9b8e1f6b46ee7c389623ff03 /pkg/gui/custom_commands.go | |
parent | 7cd17d3a73e31c6f7ab7aac69b77fbd1775d4ee5 (diff) |
better validation messages
Diffstat (limited to 'pkg/gui/custom_commands.go')
-rw-r--r-- | pkg/gui/custom_commands.go | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/pkg/gui/custom_commands.go b/pkg/gui/custom_commands.go index bf1e97b02..655e1771f 100644 --- a/pkg/gui/custom_commands.go +++ b/pkg/gui/custom_commands.go @@ -3,6 +3,7 @@ package gui import ( "bytes" "log" + "strings" "text/template" "github.com/fatih/color" @@ -211,12 +212,15 @@ func (gui *Gui) GetCustomCommandKeybindings() []*Binding { for _, customCommand := range customCommands { var viewName string - if customCommand.Context == "global" || customCommand.Context == "" { + switch customCommand.Context { + case "global": viewName = "" - } else { - context := gui.contextForContextKey(customCommand.Context) - if context == nil { - log.Fatalf("Error when setting custom command keybindings: unknown context: %s", customCommand.Context) + case "": + log.Fatalf("Error parsing custom command keybindings: context not provided (use context: 'global' for the global context). Key: %s, Command: %s", customCommand.Key, customCommand.Command) + default: + context, ok := gui.contextForContextKey(customCommand.Context) + if !ok { + log.Fatalf("Error when setting custom command keybindings: unknown context: %s. Key: %s, Command: %s.\nPermitted contexts: %s", customCommand.Context, customCommand.Key, customCommand.Command, strings.Join(allContextKeys, ", ")) } // here we assume that a given context will always belong to the same view. // Currently this is a safe bet but it's by no means guaranteed in the long term |