Skip to content

Commit

Permalink
edit main.go: getToken: fail earlier when scanning stdin fails (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
realtime-neil authored Aug 4, 2023
1 parent 9c1f16e commit 3e2251b
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,21 @@ func getToken() (string, error) {
scanner := bufio.NewScanner(os.Stdin)

fmt.Print("Enter your Duck Address: ")
var username string
if scanner.Scan() {
username = scanner.Text()
}
username = strings.TrimSpace(username)

if strings.HasSuffix(username, "@duck.com") {
username = strings.TrimSuffix(username, "@duck.com")
if !scanner.Scan() {
return "", fmt.Errorf("could not get duck address")
}
username := strings.TrimSuffix(strings.TrimSpace(scanner.Text()), "@duck.com")

err := duck.GetLoginLink(username)
if err != nil {
return "", fmt.Errorf("could not trigger OTP login link: %w", err)
}

fmt.Print("Enter the one-time passphrase sent to your email: ")
var otp string
if scanner.Scan() {
otp = scanner.Text()
if !scanner.Scan() {
return "", fmt.Errorf("could not get one-time passphrase")
}
otp = strings.TrimSpace(otp)
otp := strings.TrimSpace(scanner.Text())

loginResponse, err := duck.GetLogin(username, otp)
if err != nil {
Expand Down

0 comments on commit 3e2251b

Please sign in to comment.