mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-12 12:55:47 +02:00
better validation messages
This commit is contained in:
parent
7cd17d3a73
commit
a09bb5d4d8
5 changed files with 49 additions and 12 deletions
|
@ -176,7 +176,7 @@ func (gui *Gui) rerenderContextViewIfPresent(contextKey string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
context := gui.contextForContextKey(contextKey)
|
context := gui.mustContextForContextKey(contextKey)
|
||||||
|
|
||||||
viewName := context.GetViewName()
|
viewName := context.GetViewName()
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,29 @@ const (
|
||||||
COMMIT_MESSAGE_CONTEXT_KEY = "commitMessage"
|
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 {
|
type Context interface {
|
||||||
HandleFocus() error
|
HandleFocus() error
|
||||||
HandleFocusLost() error
|
HandleFocusLost() error
|
||||||
|
@ -674,14 +697,24 @@ type tabContext struct {
|
||||||
contexts []Context
|
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() {
|
for _, context := range gui.allContexts() {
|
||||||
if context.GetKey() == contextKey {
|
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 {
|
func (gui *Gui) rerenderView(viewName string) error {
|
||||||
|
@ -691,7 +724,7 @@ func (gui *Gui) rerenderView(viewName string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
contextKey := v.Context
|
contextKey := v.Context
|
||||||
context := gui.contextForContextKey(contextKey)
|
context := gui.mustContextForContextKey(contextKey)
|
||||||
|
|
||||||
return context.HandleRender()
|
return context.HandleRender()
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package gui
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"log"
|
"log"
|
||||||
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
|
@ -211,12 +212,15 @@ func (gui *Gui) GetCustomCommandKeybindings() []*Binding {
|
||||||
|
|
||||||
for _, customCommand := range customCommands {
|
for _, customCommand := range customCommands {
|
||||||
var viewName string
|
var viewName string
|
||||||
if customCommand.Context == "global" || customCommand.Context == "" {
|
switch customCommand.Context {
|
||||||
|
case "global":
|
||||||
viewName = ""
|
viewName = ""
|
||||||
} else {
|
case "":
|
||||||
context := gui.contextForContextKey(customCommand.Context)
|
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)
|
||||||
if context == nil {
|
default:
|
||||||
log.Fatalf("Error when setting custom command keybindings: unknown context: %s", customCommand.Context)
|
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.
|
// 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
|
// 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 {
|
if runeCount > 1 {
|
||||||
binding := keymap[strings.ToLower(key)]
|
binding := keymap[strings.ToLower(key)]
|
||||||
if binding == nil {
|
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 {
|
} else {
|
||||||
return binding
|
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 {
|
func (gui *Gui) handleRemoteEnter() error {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue