Skip to content

Commit cd15af8

Browse files
committed
feat(cli): output auth text on success only
It doesn't make sense to output Authing with ... then fail. This moves the output later in the login process to prevent that.
1 parent 1cc525a commit cd15af8

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

cli/login.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,21 @@ func (r *RootCmd) login() *clibase.Cmd {
142142
Handler: func(inv *clibase.Invocation) error {
143143
ctx := inv.Context()
144144
rawURL := ""
145+
var urlSource string
146+
145147
if len(inv.Args) == 0 {
146148
rawURL = r.clientURL.String()
149+
urlSource = "flag"
147150
if rawURL != "" && rawURL == inv.Environ.Get(envURL) {
148-
_, _ = fmt.Fprintf(inv.Stdout, "Attempting to authenticate with environment URL: %s\n", rawURL)
151+
urlSource = "environment"
149152
}
150153
} else {
151154
rawURL = inv.Args[0]
155+
urlSource = "argument"
152156
}
153157

154158
if url, err := r.createConfig().URL().Read(); rawURL == "" && err == nil {
155-
_, _ = fmt.Fprintf(inv.Stdout, "Attempting to authenticate with config URL: %s\n", url)
159+
urlSource = "config"
156160
rawURL = url
157161
}
158162

@@ -195,6 +199,9 @@ func (r *RootCmd) login() *clibase.Cmd {
195199
if err != nil {
196200
return xerrors.Errorf("Failed to check server %q for first user, is the URL correct and is coder accessible from your browser? Error - has initial user: %w", serverURL.String(), err)
197201
}
202+
203+
_, _ = fmt.Fprintf(inv.Stdout, "Attempting to authenticate with %s URL: '%s'\n", urlSource, serverURL)
204+
198205
if !hasFirstUser {
199206
_, _ = fmt.Fprintf(inv.Stdout, Caret+"Your Coder deployment hasn't been set up!\n")
200207

cli/login_test.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ func TestLogin(t *testing.T) {
116116

117117
clitest.Start(t, inv)
118118

119+
pty.ExpectMatch(fmt.Sprintf("Attempting to authenticate with flag URL: '%s'", client.URL.String()))
119120
matches := []string{
120121
"first user?", "yes",
121122
"username", "testuser",
@@ -205,6 +206,7 @@ func TestLogin(t *testing.T) {
205206
assert.NoError(t, err)
206207
}()
207208

209+
pty.ExpectMatch(fmt.Sprintf("Attempting to authenticate with argument URL: '%s'", client.URL.String()))
208210
pty.ExpectMatch("Paste your token here:")
209211
pty.WriteLine(client.SessionToken())
210212
if runtime.GOOS != "windows" {
@@ -232,14 +234,9 @@ func TestLogin(t *testing.T) {
232234
assert.NoError(t, err)
233235
}()
234236

235-
pty.ExpectMatch(fmt.Sprintf("Attempting to authenticate with config URL: %s", url))
237+
pty.ExpectMatch(fmt.Sprintf("Attempting to authenticate with config URL: '%s'", url))
236238
pty.ExpectMatch("Paste your token here:")
237239
pty.WriteLine(client.SessionToken())
238-
if runtime.GOOS != "windows" {
239-
// For some reason, the match does not show up on Windows.
240-
pty.ExpectMatch(client.SessionToken())
241-
}
242-
pty.ExpectMatch("Welcome to Coder")
243240
<-doneChan
244241
})
245242

@@ -260,14 +257,9 @@ func TestLogin(t *testing.T) {
260257
assert.NoError(t, err)
261258
}()
262259

263-
pty.ExpectMatch(fmt.Sprintf("Attempting to authenticate with environment URL: %s", url))
260+
pty.ExpectMatch(fmt.Sprintf("Attempting to authenticate with environment URL: '%s'", url))
264261
pty.ExpectMatch("Paste your token here:")
265262
pty.WriteLine(client.SessionToken())
266-
if runtime.GOOS != "windows" {
267-
// For some reason, the match does not show up on Windows.
268-
pty.ExpectMatch(client.SessionToken())
269-
}
270-
pty.ExpectMatch("Welcome to Coder")
271263
<-doneChan
272264
})
273265

0 commit comments

Comments
 (0)