Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aed4a62

Browse files
committed
Fix requested changes
1 parent 4f74b01 commit aed4a62

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

cli/login.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package cli
33
import (
44
"fmt"
55
"net/url"
6-
"os"
6+
"os/user"
77
"strings"
88

99
"github.com/fatih/color"
@@ -31,7 +31,7 @@ func login() *cobra.Command {
3131
}
3232
serverURL, err := url.Parse(rawURL)
3333
if err != nil {
34-
return err
34+
return xerrors.Errorf("parse raw url %q: %w", rawURL, err)
3535
}
3636
// Default to HTTPs. Enables simple URLs like: master.cdr.dev
3737
if serverURL.Scheme == "" {
@@ -41,37 +41,40 @@ func login() *cobra.Command {
4141
client := codersdk.New(serverURL)
4242
hasInitialUser, err := client.HasInitialUser(cmd.Context())
4343
if err != nil {
44-
return err
44+
return xerrors.Errorf("has initial user: %w", err)
4545
}
4646
if !hasInitialUser {
4747
if !isTTY(cmd.InOrStdin()) {
4848
return xerrors.New("the initial user cannot be created in non-interactive mode. use the API")
4949
}
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(">"))
5151

5252
_, err := runPrompt(cmd, &promptui.Prompt{
5353
Label: "Would you like to create the first user?",
5454
IsConfirm: true,
5555
Default: "y",
5656
})
5757
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)
5963
}
60-
6164
username, err := runPrompt(cmd, &promptui.Prompt{
6265
Label: "What username would you like?",
63-
Default: os.Getenv("USER"),
66+
Default: currentUser.Username,
6467
})
6568
if err != nil {
66-
return err
69+
return xerrors.Errorf("pick username prompt: %w", err)
6770
}
6871

6972
organization, err := runPrompt(cmd, &promptui.Prompt{
7073
Label: "What is the name of your organization?",
7174
Default: "acme-corp",
7275
})
7376
if err != nil {
74-
return err
77+
return xerrors.Errorf("pick organization prompt: %w", err)
7578
}
7679

7780
email, err := runPrompt(cmd, &promptui.Prompt{
@@ -85,15 +88,15 @@ func login() *cobra.Command {
8588
},
8689
})
8790
if err != nil {
88-
return err
91+
return xerrors.Errorf("specify email prompt: %w", err)
8992
}
9093

9194
password, err := runPrompt(cmd, &promptui.Prompt{
9295
Label: "Enter a password:",
9396
Mask: '*',
9497
})
9598
if err != nil {
96-
return err
99+
return xerrors.Errorf("specify password prompt: %w", err)
97100
}
98101

99102
_, err = client.CreateInitialUser(cmd.Context(), coderd.CreateInitialUserRequest{
@@ -122,7 +125,7 @@ func login() *cobra.Command {
122125
return xerrors.Errorf("write server url: %w", err)
123126
}
124127

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))
126129
return nil
127130
}
128131

coderd/cmd/root.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cmd
22

33
import (
44
"context"
5-
"fmt"
65
"io"
76
"io/ioutil"
87
"net"
@@ -46,11 +45,10 @@ func Root() *cobra.Command {
4645
}
4746
defer listener.Close()
4847

49-
serverURL, err := url.Parse(fmt.Sprintf("http://%s", address))
50-
if err != nil {
51-
return xerrors.Errorf("parse %q: %w", address, err)
52-
}
53-
client := codersdk.New(serverURL)
48+
client := codersdk.New(&url.URL{
49+
Scheme: "http",
50+
Host: address,
51+
})
5452
closer, err := newProvisionerDaemon(cmd.Context(), client, logger)
5553
if err != nil {
5654
return xerrors.Errorf("create provisioner daemon: %w", err)

0 commit comments

Comments
 (0)