Skip to content

Commit

Permalink
Fix reading from stdin on Windows (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
majd authored Dec 5, 2022
1 parent 5386d36 commit a3b322c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 6 additions & 2 deletions cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,16 @@ func newKeyring(logger log.Logger, passphrase string, interactive bool) (keyring

path := strings.Split(s, " unlock ")[1]
logger.Log().Msgf("enter passphrase to unlock %s (this is separate from your Apple ID password): ", path)
password, err := term.ReadPassword(int(os.Stdin.Fd()))
bytes, err := term.ReadPassword(int(os.Stdin.Fd()))
if err != nil {
return "", errors.Wrap(err, "failed to read password")
}

return string(password), nil
password := string(bytes)
password = strings.Trim(password, "\n")
password = strings.Trim(password, "\r")

return password, nil
},
})
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion pkg/appstore/appstore_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ func (a *appstore) promptForAuthCode() (string, error) {
return "", errors.Wrap(err, ErrGetData.Error())
}

return strings.Trim(authCode, "\n"), nil
authCode = strings.Trim(authCode, "\n")
authCode = strings.Trim(authCode, "\r")

return authCode, nil
}

func (*appstore) authDomain(authCode, guid string) string {
Expand Down

0 comments on commit a3b322c

Please sign in to comment.