mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-30 03:23:08 +03:00
Remove return value of Alert/Confirm/Prompt
This might seem controversial; in many cases the client code gets longer, because it needs an extra line for an explicit `return nil`. I still prefer this, because it makes it clearer which calls can return errors.
This commit is contained in:
@ -63,8 +63,8 @@ func (self *WorktreeHelper) NewWorktree() error {
|
||||
branch := self.refsHelper.GetCheckedOutRef()
|
||||
currentBranchName := branch.RefName()
|
||||
|
||||
f := func(detached bool) error {
|
||||
return self.c.Prompt(types.PromptOpts{
|
||||
f := func(detached bool) {
|
||||
self.c.Prompt(types.PromptOpts{
|
||||
Title: self.c.Tr.NewWorktreeBase,
|
||||
InitialContent: currentBranchName,
|
||||
FindSuggestionsFunc: self.suggestionsHelper.GetRefsSuggestionsFunc(),
|
||||
@ -84,13 +84,15 @@ func (self *WorktreeHelper) NewWorktree() error {
|
||||
{
|
||||
LabelColumns: []string{utils.ResolvePlaceholderString(self.c.Tr.CreateWorktreeFrom, placeholders)},
|
||||
OnPress: func() error {
|
||||
return f(false)
|
||||
f(false)
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
LabelColumns: []string{utils.ResolvePlaceholderString(self.c.Tr.CreateWorktreeFromDetached, placeholders)},
|
||||
OnPress: func() error {
|
||||
return f(true)
|
||||
f(true)
|
||||
return nil
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -114,7 +116,7 @@ func (self *WorktreeHelper) NewWorktreeCheckout(base string, canCheckoutBase boo
|
||||
})
|
||||
}
|
||||
|
||||
return self.c.Prompt(types.PromptOpts{
|
||||
self.c.Prompt(types.PromptOpts{
|
||||
Title: self.c.Tr.NewWorktreePath,
|
||||
HandleConfirm: func(path string) error {
|
||||
opts.Path = path
|
||||
@ -126,7 +128,7 @@ func (self *WorktreeHelper) NewWorktreeCheckout(base string, canCheckoutBase boo
|
||||
if canCheckoutBase {
|
||||
title := utils.ResolvePlaceholderString(self.c.Tr.NewBranchNameLeaveBlank, map[string]string{"default": base})
|
||||
// prompt for the new branch name where a blank means we just check out the branch
|
||||
return self.c.Prompt(types.PromptOpts{
|
||||
self.c.Prompt(types.PromptOpts{
|
||||
Title: title,
|
||||
HandleConfirm: func(branchName string) error {
|
||||
opts.Branch = branchName
|
||||
@ -134,9 +136,11 @@ func (self *WorktreeHelper) NewWorktreeCheckout(base string, canCheckoutBase boo
|
||||
return f()
|
||||
},
|
||||
})
|
||||
|
||||
return nil
|
||||
} else {
|
||||
// prompt for the new branch name where a blank means we just check out the branch
|
||||
return self.c.Prompt(types.PromptOpts{
|
||||
self.c.Prompt(types.PromptOpts{
|
||||
Title: self.c.Tr.NewBranchName,
|
||||
HandleConfirm: func(branchName string) error {
|
||||
if branchName == "" {
|
||||
@ -148,9 +152,13 @@ func (self *WorktreeHelper) NewWorktreeCheckout(base string, canCheckoutBase boo
|
||||
return f()
|
||||
},
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *WorktreeHelper) Switch(worktree *models.Worktree, contextKey types.ContextKey) error {
|
||||
@ -178,7 +186,7 @@ func (self *WorktreeHelper) Remove(worktree *models.Worktree, force bool) error
|
||||
},
|
||||
)
|
||||
|
||||
return self.c.Confirm(types.ConfirmOpts{
|
||||
self.c.Confirm(types.ConfirmOpts{
|
||||
Title: title,
|
||||
Prompt: message,
|
||||
HandleConfirm: func() error {
|
||||
@ -199,6 +207,8 @@ func (self *WorktreeHelper) Remove(worktree *models.Worktree, force bool) error
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *WorktreeHelper) Detach(worktree *models.Worktree) error {
|
||||
|
Reference in New Issue
Block a user