@@ -3,7 +3,7 @@ package cli
3
3
import (
4
4
"fmt"
5
5
"net/url"
6
- "os"
6
+ "os/user "
7
7
"strings"
8
8
9
9
"github.com/fatih/color"
@@ -31,7 +31,7 @@ func login() *cobra.Command {
31
31
}
32
32
serverURL , err := url .Parse (rawURL )
33
33
if err != nil {
34
- return err
34
+ return xerrors . Errorf ( "parse raw url %q: %w" , rawURL , err )
35
35
}
36
36
// Default to HTTPs. Enables simple URLs like: master.cdr.dev
37
37
if serverURL .Scheme == "" {
@@ -41,37 +41,40 @@ func login() *cobra.Command {
41
41
client := codersdk .New (serverURL )
42
42
hasInitialUser , err := client .HasInitialUser (cmd .Context ())
43
43
if err != nil {
44
- return err
44
+ return xerrors . Errorf ( "has initial user: %w" , err )
45
45
}
46
46
if ! hasInitialUser {
47
47
if ! isTTY (cmd .InOrStdin ()) {
48
48
return xerrors .New ("the initial user cannot be created in non-interactive mode. use the API" )
49
49
}
50
- _ , _ = fmt .Fprintf (cmd .OutOrStdout (), "%s Your Coder deployment hasn't been setup !\n " , color .HiBlackString (">" ))
50
+ _ , _ = fmt .Fprintf (cmd .OutOrStdout (), "%s Your Coder deployment hasn't been set up !\n " , color .HiBlackString (">" ))
51
51
52
52
_ , err := runPrompt (cmd , & promptui.Prompt {
53
53
Label : "Would you like to create the first user?" ,
54
54
IsConfirm : true ,
55
55
Default : "y" ,
56
56
})
57
57
if err != nil {
58
- return err
58
+ return xerrors .Errorf ("create user prompt: %w" , err )
59
+ }
60
+ currentUser , err := user .Current ()
61
+ if err != nil {
62
+ return xerrors .Errorf ("get current user: %w" , err )
59
63
}
60
-
61
64
username , err := runPrompt (cmd , & promptui.Prompt {
62
65
Label : "What username would you like?" ,
63
- Default : os . Getenv ( "USER" ) ,
66
+ Default : currentUser . Username ,
64
67
})
65
68
if err != nil {
66
- return err
69
+ return xerrors . Errorf ( "pick username prompt: %w" , err )
67
70
}
68
71
69
72
organization , err := runPrompt (cmd , & promptui.Prompt {
70
73
Label : "What is the name of your organization?" ,
71
74
Default : "acme-corp" ,
72
75
})
73
76
if err != nil {
74
- return err
77
+ return xerrors . Errorf ( "pick organization prompt: %w" , err )
75
78
}
76
79
77
80
email , err := runPrompt (cmd , & promptui.Prompt {
@@ -85,15 +88,15 @@ func login() *cobra.Command {
85
88
},
86
89
})
87
90
if err != nil {
88
- return err
91
+ return xerrors . Errorf ( "specify email prompt: %w" , err )
89
92
}
90
93
91
94
password , err := runPrompt (cmd , & promptui.Prompt {
92
95
Label : "Enter a password:" ,
93
96
Mask : '*' ,
94
97
})
95
98
if err != nil {
96
- return err
99
+ return xerrors . Errorf ( "specify password prompt: %w" , err )
97
100
}
98
101
99
102
_ , err = client .CreateInitialUser (cmd .Context (), coderd.CreateInitialUserRequest {
@@ -122,7 +125,7 @@ func login() *cobra.Command {
122
125
return xerrors .Errorf ("write server url: %w" , err )
123
126
}
124
127
125
- _ , _ = fmt .Fprintf (cmd .OutOrStdout (), "%s Welcome to Coder, %s! You're logged in .\n " , color .HiBlackString (">" ), color .HiCyanString (username ))
128
+ _ , _ = fmt .Fprintf (cmd .OutOrStdout (), "%s Welcome to Coder, %s! You're authenticated .\n " , color .HiBlackString (">" ), color .HiCyanString (username ))
126
129
return nil
127
130
}
128
131
0 commit comments