summaryrefslogtreecommitdiffstats
path: root/pkg/commands
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2022-01-08 14:41:30 +1100
committerJesse Duffield <jessedduffield@gmail.com>2022-01-09 14:09:53 +1100
commitfdf79fdeee71b7f281a53c72c7a0be61136bef34 (patch)
tree2ca3dee952b42db6dd17ac6654c2b1cdbe8ea85b /pkg/commands
parent0dd1c12e2f9cdf67a17058bab220ba30f7e74ed4 (diff)
fix bug that caused credentials popup to be raised unexpectedly
Diffstat (limited to 'pkg/commands')
-rw-r--r--pkg/commands/oscommands/cmd_obj_runner.go4
-rw-r--r--pkg/commands/oscommands/exec_live.go12
-rw-r--r--pkg/commands/oscommands/gui_io.go6
3 files changed, 15 insertions, 7 deletions
diff --git a/pkg/commands/oscommands/cmd_obj_runner.go b/pkg/commands/oscommands/cmd_obj_runner.go
index dbea23bf3..816e56ad6 100644
--- a/pkg/commands/oscommands/cmd_obj_runner.go
+++ b/pkg/commands/oscommands/cmd_obj_runner.go
@@ -24,9 +24,9 @@ var _ ICmdObjRunner = &cmdObjRunner{}
func (self *cmdObjRunner) runWithCredentialHandling(cmdObj ICmdObj) error {
switch cmdObj.GetCredentialStrategy() {
case PROMPT:
- return self.RunCommandWithOutputLive(cmdObj, self.guiIO.promptForCredentialFn)
+ return self.RunAndDetectCredentialRequest(cmdObj, self.guiIO.promptForCredentialFn)
case FAIL:
- return self.RunCommandWithOutputLive(cmdObj, func(s string) string { return "\n" })
+ return self.RunAndDetectCredentialRequest(cmdObj, func(CredentialName) string { return "\n" })
}
// we should never land here
diff --git a/pkg/commands/oscommands/exec_live.go b/pkg/commands/oscommands/exec_live.go
index 21c1c8d27..3526cdbd2 100644
--- a/pkg/commands/oscommands/exec_live.go
+++ b/pkg/commands/oscommands/exec_live.go
@@ -13,15 +13,23 @@ import (
"github.com/jesseduffield/lazygit/pkg/utils"
)
+type CredentialName string
+
+const (
+ Password CredentialName = "password"
+ Username = "username"
+ Passphrase = "passphrase"
+)
+
// RunAndDetectCredentialRequest detect a username / password / passphrase question in a command
// promptUserForCredential is a function that gets executed when this function detect you need to fillin a password or passphrase
// The promptUserForCredential argument will be "username", "password" or "passphrase" and expects the user's password/passphrase or username back
-func (self *cmdObjRunner) RunAndDetectCredentialRequest(cmdObj ICmdObj, promptUserForCredential func(string) string) error {
+func (self *cmdObjRunner) RunAndDetectCredentialRequest(cmdObj ICmdObj, promptUserForCredential func(CredentialName) string) error {
ttyText := ""
err := self.RunCommandWithOutputLive(cmdObj, func(word string) string {
ttyText = ttyText + " " + word
- prompts := map[string]string{
+ prompts := map[string]CredentialName{
`.+'s password:`: "password",
`Password\s*for\s*'.+':`: "password",
`Username\s*for\s*'.+':`: "username",
diff --git a/pkg/commands/oscommands/gui_io.go b/pkg/commands/oscommands/gui_io.go
index ec42f90b3..5a174d46c 100644
--- a/pkg/commands/oscommands/gui_io.go
+++ b/pkg/commands/oscommands/gui_io.go
@@ -27,10 +27,10 @@ type guiIO struct {
// this allows us to request info from the user like username/password, in the event
// that a command requests it.
// the 'credential' arg is something like 'username' or 'password'
- promptForCredentialFn func(credential string) string
+ promptForCredentialFn func(credential CredentialName) string
}
-func NewGuiIO(log *logrus.Entry, logCommandFn func(string, bool), newCmdWriterFn func() io.Writer, promptForCredentialFn func(string) string) *guiIO {
+func NewGuiIO(log *logrus.Entry, logCommandFn func(string, bool), newCmdWriterFn func() io.Writer, promptForCredentialFn func(CredentialName) string) *guiIO {
return &guiIO{
log: log,
logCommandFn: logCommandFn,
@@ -44,6 +44,6 @@ func NewNullGuiIO(log *logrus.Entry) *guiIO {
log: log,
logCommandFn: func(string, bool) {},
newCmdWriterFn: func() io.Writer { return ioutil.Discard },
- promptForCredentialFn: func(string) string { return "" },
+ promptForCredentialFn: func(CredentialName) string { return "" },
}
}