Skip to content

Commit

Permalink
Input username and password
Browse files Browse the repository at this point in the history
  • Loading branch information
cyp0633 committed Mar 10, 2023
1 parent 9d68155 commit 68377f8
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion internal/dhcp/auto/auto.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
func Auto() {
fmt.Printf("We'll go through some steps to generate configuration automatically.\n")
_ = selectVersion()
util.Conf.Username = inputAccount()
util.Conf.Password = inputPassword()
}

// selectVersion 选择 Dr.com 客户端版本
Expand All @@ -24,7 +26,7 @@ func selectVersion() int {
}
_, result, err = prompt.Run()
if err != nil {
util.Logger.Error("Prompt failed", zap.Error(err))
util.Logger.Error("Select version failed", zap.Error(err))
} else {
break
}
Expand All @@ -44,3 +46,40 @@ const (
Drcom52D = iota
Drcom60D = iota
)

// inputAccount 输入账号
func inputAccount() string {
var result string
for err := error(nil); ; {
prompt := promptui.Prompt{
Label: "Username",
Validate: func(input string) error { return nil },
}
result, err = prompt.Run()
if err != nil {
util.Logger.Error("Input username prompt failed", zap.Error(err))
} else {
break
}
}
return result
}

// inputPassword 输入密码
func inputPassword() string {
var result string
for err := error(nil); ; {
prompt := promptui.Prompt{
Label: "Password",
Validate: func(input string) error { return nil },
Mask: '*',
}
result, err = prompt.Run()
if err != nil {
util.Logger.Error("Input password prompt failed", zap.Error(err))
} else {
break
}
}
return result
}

0 comments on commit 68377f8

Please sign in to comment.