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:
parent
18bcc0df4d
commit
500267417b
@ -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 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user