1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-15 11:56:37 +02:00

Removed some duplicated code

This commit is contained in:
mjarkk 2018-11-10 08:46:42 +01:00
parent 18bcc0df4d
commit 500267417b

View File

@ -69,21 +69,20 @@ func (c *OSCommand) DetectUnamePass(command string, ask func(string) string) err
errMessage, err := c.RunCommandWithOutputLive(command, func(word string) string { errMessage, err := c.RunCommandWithOutputLive(command, func(word string) string {
ttyText = ttyText + " " + word ttyText = ttyText + " " + word
// detect username question // prompt and patterns to check if the user needs to input a username / password
detectUname, _ := regexp.MatchString(`Username\s*for\s*'.+':`, ttyText) prompts := map[string]string{
if detectUname { "password": `Password\s*for\s*'.+':`,
// reset the text and return the user's username "username": `Username\s*for\s*'.+':`,
ttyText = ""
return ask("username")
} }
// detect password question for prompt, pattern := range prompts {
detectPass, _ := regexp.MatchString(`Password\s*for\s*'.+':`, ttyText) match, _ := regexp.MatchString(pattern, ttyText)
if detectPass { if match {
// reset the text and return the user's username ttyText = ""
ttyText = "" return ask(prompt)
return ask("password") }
} }
return "" return ""
}) })
if err != nil { if err != nil {