Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 996a3cd

Browse files
authored
Fix coder login on Windows (#310)
* switch to scanner for token * fix spacing * ignore return value from scanner.Scan()
1 parent 05f9410 commit 996a3cd

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

internal/cmd/login.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bufio"
55
"context"
66
"fmt"
7-
"io"
87
"net/url"
98
"strings"
109

@@ -73,7 +72,15 @@ func login(cmd *cobra.Command, envURL *url.URL) error {
7372
fmt.Printf("Your browser has been opened to visit:\n\n\t%s\n\n", authURL.String())
7473
}
7574

76-
token := readLine("Paste token here: ", cmd.InOrStdin())
75+
fmt.Print("Paste token here: ")
76+
var token string
77+
scanner := bufio.NewScanner(cmd.InOrStdin())
78+
_ = scanner.Scan()
79+
token = scanner.Text()
80+
if err := scanner.Err(); err != nil {
81+
return xerrors.Errorf("reading standard input: %w", err)
82+
}
83+
7784
if err := pingAPI(cmd.Context(), envURL, token); err != nil {
7885
return xerrors.Errorf("ping API with credentials: %w", err)
7986
}
@@ -84,13 +91,6 @@ func login(cmd *cobra.Command, envURL *url.URL) error {
8491
return nil
8592
}
8693

87-
func readLine(prompt string, r io.Reader) string {
88-
reader := bufio.NewReader(r)
89-
fmt.Print(prompt)
90-
text, _ := reader.ReadString('\n')
91-
return strings.TrimSuffix(text, "\n")
92-
}
93-
9494
// pingAPI creates a client from the given url/token and try to exec an api call.
9595
// Not using the SDK as we want to verify the url/token pair before storing the config files.
9696
func pingAPI(ctx context.Context, envURL *url.URL, token string) error {

0 commit comments

Comments
 (0)