summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authormjarkk <mkopenga@gmail.com>2018-11-10 08:46:42 +0100
committermjarkk <mkopenga@gmail.com>2018-11-10 08:46:42 +0100
commit500267417b9779822e908ba7997f9adb9c881cac (patch)
treea00acb7d1adb7be6c63c80e3a06ef700bd56752d /pkg
parent18bcc0df4d28f84086e9f5ecb1771e6afc582fc9 (diff)
Removed some duplicated code
Diffstat (limited to 'pkg')
-rw-r--r--pkg/commands/os.go23
1 files changed, 11 insertions, 12 deletions
diff --git a/pkg/commands/os.go b/pkg/commands/os.go
index 05b11a62e..65e25271b 100644
--- a/pkg/commands/os.go
+++ b/pkg/commands/os.go
@@ -69,21 +69,20 @@ func (c *OSCommand) DetectUnamePass(command string, ask func(string) string) err
errMessage, err := c.RunCommandWithOutputLive(command, func(word string) string {
ttyText = ttyText + " " + word
- // detect username question
- detectUname, _ := regexp.MatchString(`Username\s*for\s*'.+':`, ttyText)
- if detectUname {
- // reset the text and return the user's username
- ttyText = ""
- return ask("username")
+ // prompt and patterns to check if the user needs to input a username / password
+ prompts := map[string]string{
+ "password": `Password\s*for\s*'.+':`,
+ "username": `Username\s*for\s*'.+':`,
}
- // detect password question
- detectPass, _ := regexp.MatchString(`Password\s*for\s*'.+':`, ttyText)
- if detectPass {
- // reset the text and return the user's username
- ttyText = ""
- return ask("password")
+ for prompt, pattern := range prompts {
+ match, _ := regexp.MatchString(pattern, ttyText)
+ if match {
+ ttyText = ""
+ return ask(prompt)
+ }
}
+
return ""
})
if err != nil {