Skip to content

feat: expose premium trial form via CLI #15054

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove trial params as env
  • Loading branch information
joobisb committed Oct 16, 2024
commit af7cf3b10ee5265e0c10fcc1c73f46eee7cbfed0
99 changes: 21 additions & 78 deletions cli/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,6 @@ func (r *RootCmd) login() *serpent.Command {
password string
trial bool
useTokenForSession bool

firstName string
lastName string
phoneNumber string
jobTitle string
companyName string
country string
developers string
)
cmd := &serpent.Command{
Use: "login [<url>]",
Expand Down Expand Up @@ -275,66 +267,59 @@ func (r *RootCmd) login() *serpent.Command {
trial = v == "yes" || v == "y"
}

var trialInfo codersdk.CreateFirstUserTrialInfo
if trial {
if firstName == "" {
firstName, err = promptTrialInfo(inv, "firstName")
if trialInfo.FirstName == "" {
trialInfo.FirstName, err = promptTrialInfo(inv, "firstName")
if err != nil {
return err
}
}
if lastName == "" {
lastName, err = promptTrialInfo(inv, "lastName")
if trialInfo.LastName == "" {
trialInfo.LastName, err = promptTrialInfo(inv, "lastName")
if err != nil {
return err
}
}
if phoneNumber == "" {
phoneNumber, err = promptTrialInfo(inv, "phoneNumber")
if trialInfo.PhoneNumber == "" {
trialInfo.PhoneNumber, err = promptTrialInfo(inv, "phoneNumber")
if err != nil {
return err
}
}
if jobTitle == "" {
jobTitle, err = promptTrialInfo(inv, "jobTitle")
if trialInfo.JobTitle == "" {
trialInfo.JobTitle, err = promptTrialInfo(inv, "jobTitle")
if err != nil {
return err
}
}
if companyName == "" {
companyName, err = promptTrialInfo(inv, "companyName")
if trialInfo.CompanyName == "" {
trialInfo.CompanyName, err = promptTrialInfo(inv, "companyName")
if err != nil {
return err
}
}
if country == "" {
country, err = promptCountry(inv)
if trialInfo.Country == "" {
trialInfo.Country, err = promptCountry(inv)
if err != nil {
return err
}
}
if developers == "" {
developers, err = promptDevelopers(inv)
if trialInfo.Developers == "" {
trialInfo.Developers, err = promptDevelopers(inv)
if err != nil {
return err
}
}
}

_, err = client.CreateFirstUser(ctx, codersdk.CreateFirstUserRequest{
Email: email,
Username: username,
Name: name,
Password: password,
Trial: trial,
TrialInfo: codersdk.CreateFirstUserTrialInfo{
FirstName: firstName,
LastName: lastName,
PhoneNumber: phoneNumber,
JobTitle: jobTitle,
CompanyName: companyName,
Country: country,
Developers: developers,
},
Email: email,
Username: username,
Name: name,
Password: password,
Trial: trial,
TrialInfo: trialInfo,
})
if err != nil {
return xerrors.Errorf("create initial user: %w", err)
Expand Down Expand Up @@ -460,48 +445,6 @@ func (r *RootCmd) login() *serpent.Command {
Description: "By default, the CLI will generate a new session token when logging in. This flag will instead use the provided token as the session token.",
Value: serpent.BoolOf(&useTokenForSession),
},
{
Flag: "first-user-first-name",
Env: "CODER_FIRST_USER_FIRST_NAME",
Description: "Specifies the first name of the user.",
Value: serpent.StringOf(&firstName),
},
{
Flag: "first-user-last-name",
Env: "CODER_FIRST_USER_LAST_NAME",
Description: "Specifies the last name of the user.",
Value: serpent.StringOf(&lastName),
},
{
Flag: "first-user-phone-number",
Env: "CODER_FIRST_USER_PHONE_NUMBER",
Description: "Specifies the phone number of the user.",
Value: serpent.StringOf(&phoneNumber),
},
{
Flag: "first-user-job-title",
Env: "CODER_FIRST_USER_JOB_TITLE",
Description: "Specifies the job title of the user.",
Value: serpent.StringOf(&jobTitle),
},
{
Flag: "first-user-company-name",
Env: "CODER_FIRST_USER_COMPANY_NAME",
Description: "Specifies the company name of the user.",
Value: serpent.StringOf(&companyName),
},
{
Flag: "first-user-country",
Env: "CODER_FIRST_USER_COUNTRY",
Description: "Specifies the country of the user.",
Value: serpent.StringOf(&country),
},
{
Flag: "first-user-developers",
Env: "CODER_FIRST_USER_DEVELOPERS",
Description: "Specifies the number of developers.",
Value: serpent.StringOf(&developers),
},
}
return cmd
}
Expand Down
37 changes: 22 additions & 15 deletions cli/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,16 +281,20 @@ func TestLogin(t *testing.T) {
"--first-user-email", coderdtest.FirstUserParams.Email,
"--first-user-password", coderdtest.FirstUserParams.Password,
"--first-user-trial",
"--first-user-first-name", coderdtest.TrialUserParams.FirstName,
"--first-user-last-name", coderdtest.TrialUserParams.LastName,
"--first-user-phone-number", coderdtest.TrialUserParams.PhoneNumber,
"--first-user-job-title", coderdtest.TrialUserParams.JobTitle,
"--first-user-company-name", coderdtest.TrialUserParams.CompanyName,
"--first-user-country", coderdtest.TrialUserParams.Country,
"--first-user-developers", coderdtest.TrialUserParams.Developers,
)
pty := ptytest.New(t).Attach(inv)
w := clitest.StartWithWaiter(t, inv)
pty.ExpectMatch("firstName")
pty.WriteLine(coderdtest.TrialUserParams.FirstName)
pty.ExpectMatch("lastName")
pty.WriteLine(coderdtest.TrialUserParams.LastName)
pty.ExpectMatch("phoneNumber")
pty.WriteLine(coderdtest.TrialUserParams.PhoneNumber)
pty.ExpectMatch("jobTitle")
pty.WriteLine(coderdtest.TrialUserParams.JobTitle)
pty.ExpectMatch("companyName")
pty.WriteLine(coderdtest.TrialUserParams.CompanyName)
// `developers` and `country` `cliui.Select` automatically selects the first option during tests.
pty.ExpectMatch("Welcome to Coder")
w.RequireSuccess()
ctx := testutil.Context(t, testutil.WaitShort)
Expand All @@ -316,17 +320,20 @@ func TestLogin(t *testing.T) {
"--first-user-email", coderdtest.FirstUserParams.Email,
"--first-user-password", coderdtest.FirstUserParams.Password,
"--first-user-trial",
"--first-user-first-name", coderdtest.TrialUserParams.FirstName,
"--first-user-last-name", coderdtest.TrialUserParams.LastName,
"--first-user-phone-number", coderdtest.TrialUserParams.PhoneNumber,
"--first-user-job-title", coderdtest.TrialUserParams.JobTitle,
"--first-user-company-name", coderdtest.TrialUserParams.CompanyName,
"--first-user-country", coderdtest.TrialUserParams.Country,
"--first-user-developers", coderdtest.TrialUserParams.Developers,
// `developers` and `country` `cliui.Select` automatically selects the first option during tests.
)
pty := ptytest.New(t).Attach(inv)
w := clitest.StartWithWaiter(t, inv)
pty.ExpectMatch("firstName")
pty.WriteLine(coderdtest.TrialUserParams.FirstName)
pty.ExpectMatch("lastName")
pty.WriteLine(coderdtest.TrialUserParams.LastName)
pty.ExpectMatch("phoneNumber")
pty.WriteLine(coderdtest.TrialUserParams.PhoneNumber)
pty.ExpectMatch("jobTitle")
pty.WriteLine(coderdtest.TrialUserParams.JobTitle)
pty.ExpectMatch("companyName")
pty.WriteLine(coderdtest.TrialUserParams.CompanyName)
// `developers` and `country` `cliui.Select` automatically selects the first option during tests.
pty.ExpectMatch("Welcome to Coder")
w.RequireSuccess()
ctx := testutil.Context(t, testutil.WaitShort)
Expand Down
21 changes: 0 additions & 21 deletions cli/testdata/coder_login_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,17 @@ USAGE:
Authenticate with Coder deployment

OPTIONS:
--first-user-company-name string, $CODER_FIRST_USER_COMPANY_NAME
Specifies the company name of the user.

--first-user-country string, $CODER_FIRST_USER_COUNTRY
Specifies the country of the user.

--first-user-developers string, $CODER_FIRST_USER_DEVELOPERS
Specifies the number of developers.

--first-user-email string, $CODER_FIRST_USER_EMAIL
Specifies an email address to use if creating the first user for the
deployment.

--first-user-first-name string, $CODER_FIRST_USER_FIRST_NAME
Specifies the first name of the user.

--first-user-full-name string, $CODER_FIRST_USER_FULL_NAME
Specifies a human-readable name for the first user of the deployment.

--first-user-job-title string, $CODER_FIRST_USER_JOB_TITLE
Specifies the job title of the user.

--first-user-last-name string, $CODER_FIRST_USER_LAST_NAME
Specifies the last name of the user.

--first-user-password string, $CODER_FIRST_USER_PASSWORD
Specifies a password to use if creating the first user for the
deployment.

--first-user-phone-number string, $CODER_FIRST_USER_PHONE_NUMBER
Specifies the phone number of the user.

--first-user-trial bool, $CODER_FIRST_USER_TRIAL
Specifies whether a trial license should be provisioned for the Coder
deployment or not.
Expand Down
63 changes: 0 additions & 63 deletions docs/reference/cli/login.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.