Skip to content

Commit a3b322c

Browse files
authored
Fix reading from stdin on Windows (#121)
1 parent 5386d36 commit a3b322c

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

cmd/common.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,16 @@ func newKeyring(logger log.Logger, passphrase string, interactive bool) (keyring
6969

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

77-
return string(password), nil
77+
password := string(bytes)
78+
password = strings.Trim(password, "\n")
79+
password = strings.Trim(password, "\r")
80+
81+
return password, nil
7882
},
7983
})
8084
if err != nil {

pkg/appstore/appstore_login.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ func (a *appstore) promptForAuthCode() (string, error) {
171171
return "", errors.Wrap(err, ErrGetData.Error())
172172
}
173173

174-
return strings.Trim(authCode, "\n"), nil
174+
authCode = strings.Trim(authCode, "\n")
175+
authCode = strings.Trim(authCode, "\r")
176+
177+
return authCode, nil
175178
}
176179

177180
func (*appstore) authDomain(authCode, guid string) string {

0 commit comments

Comments
 (0)