mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-01-04 03:48:07 +02:00
better validation messages
This commit is contained in:
parent
7cd17d3a73
commit
a09bb5d4d8
@ -176,7 +176,7 @@ func (gui *Gui) rerenderContextViewIfPresent(contextKey string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
context := gui.contextForContextKey(contextKey)
|
||||
context := gui.mustContextForContextKey(contextKey)
|
||||
|
||||
viewName := context.GetViewName()
|
||||
|
||||
|
@ -36,6 +36,29 @@ const (
|
||||
COMMIT_MESSAGE_CONTEXT_KEY = "commitMessage"
|
||||
)
|
||||
|
||||
var allContextKeys = []string{
|
||||
STATUS_CONTEXT_KEY,
|
||||
FILES_CONTEXT_KEY,
|
||||
LOCAL_BRANCHES_CONTEXT_KEY,
|
||||
REMOTES_CONTEXT_KEY,
|
||||
REMOTE_BRANCHES_CONTEXT_KEY,
|
||||
TAGS_CONTEXT_KEY,
|
||||
BRANCH_COMMITS_CONTEXT_KEY,
|
||||
REFLOG_COMMITS_CONTEXT_KEY,
|
||||
SUB_COMMITS_CONTEXT_KEY,
|
||||
COMMIT_FILES_CONTEXT_KEY,
|
||||
STASH_CONTEXT_KEY,
|
||||
MAIN_NORMAL_CONTEXT_KEY,
|
||||
MAIN_MERGING_CONTEXT_KEY,
|
||||
MAIN_PATCH_BUILDING_CONTEXT_KEY,
|
||||
MAIN_STAGING_CONTEXT_KEY,
|
||||
MENU_CONTEXT_KEY,
|
||||
CREDENTIALS_CONTEXT_KEY,
|
||||
CONFIRMATION_CONTEXT_KEY,
|
||||
SEARCH_CONTEXT_KEY,
|
||||
COMMIT_MESSAGE_CONTEXT_KEY,
|
||||
}
|
||||
|
||||
type Context interface {
|
||||
HandleFocus() error
|
||||
HandleFocusLost() error
|
||||
@ -674,14 +697,24 @@ type tabContext struct {
|
||||
contexts []Context
|
||||
}
|
||||
|
||||
func (gui *Gui) contextForContextKey(contextKey string) Context {
|
||||
func (gui *Gui) mustContextForContextKey(contextKey string) Context {
|
||||
context, ok := gui.contextForContextKey(contextKey)
|
||||
|
||||
if !ok {
|
||||
panic(fmt.Sprintf("context now found for key %s", contextKey))
|
||||
}
|
||||
|
||||
return context
|
||||
}
|
||||
|
||||
func (gui *Gui) contextForContextKey(contextKey string) (Context, bool) {
|
||||
for _, context := range gui.allContexts() {
|
||||
if context.GetKey() == contextKey {
|
||||
return context
|
||||
return context, true
|
||||
}
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("context now found for key %s", contextKey))
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func (gui *Gui) rerenderView(viewName string) error {
|
||||
@ -691,7 +724,7 @@ func (gui *Gui) rerenderView(viewName string) error {
|
||||
}
|
||||
|
||||
contextKey := v.Context
|
||||
context := gui.contextForContextKey(contextKey)
|
||||
context := gui.mustContextForContextKey(contextKey)
|
||||
|
||||
return context.HandleRender()
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -189,7 +189,7 @@ func (gui *Gui) getKey(name string) interface{} {
|
||||
if runeCount > 1 {
|
||||
binding := keymap[strings.ToLower(key)]
|
||||
if binding == nil {
|
||||
log.Fatalf("Unrecognized key %s for keybinding %s", strings.ToLower(key), name)
|
||||
log.Fatalf("Unrecognized key %s for keybinding %s. For permitted values see https://github.com/jesseduffield/lazygit/blob/master/docs/keybindings/Custom_Keybindings.md", strings.ToLower(key), name)
|
||||
} else {
|
||||
return binding
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ func (gui *Gui) refreshRemotes() error {
|
||||
}
|
||||
}
|
||||
|
||||
return gui.postRefreshUpdate(gui.contextForContextKey(gui.getBranchesView().Context))
|
||||
return gui.postRefreshUpdate(gui.mustContextForContextKey(gui.getBranchesView().Context))
|
||||
}
|
||||
|
||||
func (gui *Gui) handleRemoteEnter() error {
|
||||
|
Loading…
Reference in New Issue
Block a user