Skip to content

Commit d028e1e

Browse files
committed
162 problems left...
The end is in sight
1 parent 6c0b64a commit d028e1e

File tree

13 files changed

+172
-103
lines changed

13 files changed

+172
-103
lines changed

cli/login.go

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"golang.org/x/xerrors"
1818

1919
"github.com/coder/coder/cli/clibase"
20-
"github.com/coder/coder/cli/cliflag"
2120
"github.com/coder/coder/cli/cliui"
2221
"github.com/coder/coder/coderd/userpassword"
2322
"github.com/coder/coder/codersdk"
@@ -178,7 +177,7 @@ func (r *RootCmd) login() *clibase.Cmd {
178177
}
179178
}
180179

181-
if !cmd.Flags().Changed("first-user-trial") && os.Getenv(firstUserTrialEnv) == "" {
180+
if !inv.ParsedFlags().Changed("first-user-trial") && os.Getenv(firstUserTrialEnv) == "" {
182181
v, _ := cliui.Prompt(inv, cliui.PromptOptions{
183182
Text: "Start a 30-day trial of Enterprise?",
184183
IsConfirm: true,
@@ -273,10 +272,32 @@ func (r *RootCmd) login() *clibase.Cmd {
273272
return nil
274273
},
275274
}
276-
cliflag.StringVarP(cmd.Flags(), &email, "first-user-email", "", "CODER_FIRST_USER_EMAIL", "", "Specifies an email address to use if creating the first user for the deployment.")
277-
cliflag.StringVarP(cmd.Flags(), &username, "first-user-username", "", "CODER_FIRST_USER_USERNAME", "", "Specifies a username to use if creating the first user for the deployment.")
278-
cliflag.StringVarP(cmd.Flags(), &password, "first-user-password", "", "CODER_FIRST_USER_PASSWORD", "", "Specifies a password to use if creating the first user for the deployment.")
279-
cliflag.BoolVarP(cmd.Flags(), &trial, "first-user-trial", "", firstUserTrialEnv, false, "Specifies whether a trial license should be provisioned for the Coder deployment or not.")
275+
cmd.Options = []clibase.Option{
276+
{
277+
Flag: "first-user-email",
278+
Env: "CODER_FIRST_USER_EMAIL",
279+
Description: "Specifies an email address to use if creating the first user for the deployment.",
280+
Value: clibase.StringOf(&email),
281+
},
282+
{
283+
Flag: "first-user-username",
284+
Env: "CODER_FIRST_USER_USERNAME",
285+
Description: "Specifies a username to use if creating the first user for the deployment.",
286+
Value: clibase.StringOf(&username),
287+
},
288+
{
289+
Flag: "first-user-password",
290+
Env: "CODER_FIRST_USER_PASSWORD",
291+
Description: "Specifies a password to use if creating the first user for the deployment.",
292+
Value: clibase.StringOf(&password),
293+
},
294+
{
295+
Flag: "first-user-trial",
296+
Env: firstUserTrialEnv,
297+
Description: "Specifies whether a trial license should be provisioned for the Coder deployment or not.",
298+
Value: clibase.BoolOf(&trial),
299+
},
300+
}
280301
return cmd
281302
}
282303

cli/logout.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,23 @@ import (
99

1010
"github.com/coder/coder/cli/clibase"
1111
"github.com/coder/coder/cli/cliui"
12+
"github.com/coder/coder/codersdk"
1213
)
1314

1415
func (r *RootCmd) logout() *clibase.Cmd {
16+
client := new(codersdk.Client)
1517
cmd := &clibase.Cmd{
16-
Use: "logout",
17-
Short: "Unauthenticate your local session",
18-
Middleware: clibase.Chain(r.UseClient(client)),
18+
Use: "logout",
19+
Short: "Unauthenticate your local session",
20+
Middleware: clibase.Chain(
21+
r.UseClient(client),
22+
),
1923
Handler: func(inv *clibase.Invokation) error {
2024
var errors []error
2125

2226
config := r.createConfig()
2327

28+
var err error
2429
_, err = cliui.Prompt(inv, cliui.PromptOptions{
2530
Text: "Are you sure you want to log out?",
2631
IsConfirm: true,
@@ -67,7 +72,6 @@ func (r *RootCmd) logout() *clibase.Cmd {
6772
return nil
6873
},
6974
}
70-
71-
cliui.SkipPromptOption(inv)
75+
cmd.Options = append(cmd.Options, cliui.SkipPromptOption())
7276
return cmd
7377
}

cli/parameters.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ func (r *RootCmd) parameters() *clibase.Cmd {
2323
Handler: func(inv *clibase.Invokation) error {
2424
return inv.Command.HelpHandler(inv)
2525
},
26+
Children: []*clibase.Cmd{
27+
r.parameterList(),
28+
},
2629
}
27-
cmd.AddCommand(
28-
parameterList(),
29-
)
3030
return cmd
3131
}

cli/ping.go

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717

1818
func (r *RootCmd) ping() *clibase.Cmd {
1919
var (
20-
pingNum int
20+
pingNum int64
2121
pingTimeout time.Duration
2222
pingWait time.Duration
2323
verbose bool
@@ -37,7 +37,10 @@ func (r *RootCmd) ping() *clibase.Cmd {
3737
defer cancel()
3838

3939
workspaceName := inv.Args[0]
40-
_, workspaceAgent, err := getWorkspaceAndAgent(ctx, cmd, client, codersdk.Me, workspaceName, false)
40+
_, workspaceAgent, err := getWorkspaceAndAgent(
41+
ctx, inv, client,
42+
codersdk.Me, workspaceName, false,
43+
)
4144
if err != nil {
4245
return err
4346
}
@@ -71,7 +74,7 @@ func (r *RootCmd) ping() *clibase.Cmd {
7174
if err != nil {
7275
if xerrors.Is(err, context.DeadlineExceeded) {
7376
_, _ = fmt.Fprintf(inv.Stdout, "ping to %q timed out \n", workspaceName)
74-
if n == pingNum {
77+
if n == int(pingNum) {
7578
return nil
7679
}
7780
continue
@@ -85,7 +88,7 @@ func (r *RootCmd) ping() *clibase.Cmd {
8588
}
8689

8790
_, _ = fmt.Fprintf(inv.Stdout, "ping to %q failed %s\n", workspaceName, err.Error())
88-
if n == pingNum {
91+
if n == int(pingNum) {
8992
return nil
9093
}
9194
continue
@@ -123,16 +126,39 @@ func (r *RootCmd) ping() *clibase.Cmd {
123126
cliui.Styles.DateTimeStamp.Render(dur.String()),
124127
)
125128

126-
if n == pingNum {
129+
if n == int(pingNum) {
127130
return nil
128131
}
129132
}
130133
},
131134
}
132135

133-
cmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "Enables verbose logging.")
134-
cmd.Flags().DurationVarP(&pingWait, "wait", "", time.Second, "Specifies how long to wait between pings.")
135-
cmd.Flags().DurationVarP(&pingTimeout, "timeout", "t", 5*time.Second, "Specifies how long to wait for a ping to complete.")
136-
cmd.Flags().IntVarP(&pingNum, "num", "n", 10, "Specifies the number of pings to perform.")
136+
cmd.Options = []clibase.Option{
137+
{
138+
Flag: "verbose",
139+
FlagShorthand: "v",
140+
Description: "Enables verbose logging.",
141+
Value: clibase.BoolOf(&verbose),
142+
},
143+
{
144+
Flag: "wait",
145+
Description: "Specifies how long to wait between pings.",
146+
Value: clibase.DurationOf(&pingWait),
147+
},
148+
{
149+
Flag: "timeout",
150+
FlagShorthand: "t",
151+
Default: "5s",
152+
Description: "Specifies how long to wait for a ping to complete.",
153+
Value: clibase.DurationOf(&pingTimeout),
154+
},
155+
{
156+
Flag: "num",
157+
FlagShorthand: "n",
158+
Default: "10",
159+
Description: "Specifies the number of pings to perform.",
160+
Value: clibase.Int64Of(&pingNum),
161+
},
162+
}
137163
return cmd
138164
}

cli/publickey.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,27 @@ func (r *RootCmd) publickey() *clibase.Cmd {
4343
return xerrors.Errorf("create codersdk client: %w", err)
4444
}
4545

46-
cmd.Println(cliui.Styles.Wrap.Render(
47-
"This is your public key for using " + cliui.Styles.Field.Render("git") + " in " +
48-
"Coder. All clones with SSH will be authenticated automatically 🪄.",
49-
))
50-
cmd.Println()
51-
cliui.Infof(inv.Stdout, cliui.Styles.Code.Render(strings.TrimSpace(key.PublicKey))+"\n")
52-
cmd.Println()
46+
cliui.Infof(inv.Stdout,
47+
"This is your public key for using "+cliui.Styles.Field.Render("git")+" in "+
48+
"Coder. All clones with SSH will be authenticated automatically 🪄.\n\n",
49+
)
50+
cliui.Infof(inv.Stdout, cliui.Styles.Code.Render(strings.TrimSpace(key.PublicKey))+"\n\n")
5351
cliui.Infof(inv.Stdout, "Add to GitHub and GitLab:"+"\n")
5452
cliui.Infof(inv.Stdout, cliui.Styles.Prompt.String()+"https://github.com/settings/ssh/new"+"\n")
5553
cliui.Infof(inv.Stdout, cliui.Styles.Prompt.String()+"https://gitlab.com/-/profile/keys"+"\n")
5654

5755
return nil
5856
},
5957
}
60-
cmd.Flags().BoolVar(&reset, "reset", false, "Regenerate your public key. This will require updating the key on any services it's registered with.")
61-
cliui.SkipPromptOption(inv)
58+
59+
cmd.Options = clibase.OptionSet{
60+
{
61+
Flag: "reset",
62+
Description: "Regenerate your public key. This will require updating the key on any services it's registered with.",
63+
Value: clibase.BoolOf(&reset),
64+
},
65+
cliui.SkipPromptOption(),
66+
}
6267

6368
return cmd
6469
}

cli/rename.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ import (
1111
)
1212

1313
func (r *RootCmd) rename() *clibase.Cmd {
14+
client := new(codersdk.Client)
1415
cmd := &clibase.Cmd{
1516
Annotations: workspaceCommand,
1617
Use: "rename <workspace> <new name>",
1718
Short: "Rename a workspace",
18-
Middleware: clibase.RequireNArgs(2),
19-
Middleware: clibase.Chain(r.UseClient(client)),
19+
Middleware: clibase.Chain(
20+
clibase.RequireNArgs(2),
21+
r.UseClient(client),
22+
),
2023
Handler: func(inv *clibase.Invokation) error {
2124
workspace, err := namedWorkspace(inv.Context(), client, inv.Args[0])
2225
if err != nil {
@@ -50,7 +53,7 @@ func (r *RootCmd) rename() *clibase.Cmd {
5053
},
5154
}
5255

53-
cliui.SkipPromptOption(inv)
56+
cmd.Options = append(cmd.Options, cliui.SkipPromptOption())
5457

5558
return cmd
5659
}

cli/templateversions.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ func (r *RootCmd) templateVersions() *clibase.Cmd {
2727
Handler: func(inv *clibase.Invokation) error {
2828
return inv.Command.HelpHandler(inv)
2929
},
30+
Children: []*clibase.Cmd{
31+
r.templateVersionsList(),
32+
},
3033
}
31-
cmd.AddCommand(
32-
templateVersionsList(),
33-
)
3434

3535
return cmd
3636
}

cli/userlist.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"time"
77

88
"github.com/jedib0t/go-pretty/v6/table"
9+
"github.com/spf13/pflag"
910
"golang.org/x/xerrors"
1011

1112
"github.com/coder/coder/cli/clibase"
@@ -49,6 +50,7 @@ func (r *RootCmd) userSingle() *clibase.Cmd {
4950
&userShowFormat{},
5051
cliui.JSONFormat(),
5152
)
53+
client := new(codersdk.Client)
5254

5355
cmd := &clibase.Cmd{
5456
Use: "show <username|user_id|'me'>",
@@ -58,8 +60,10 @@ func (r *RootCmd) userSingle() *clibase.Cmd {
5860
Command: "coder users show me",
5961
},
6062
),
61-
Middleware: clibase.RequireNArgs(1),
62-
Middleware: clibase.Chain(r.UseClient(client)),
63+
Middleware: clibase.Chain(
64+
clibase.RequireNArgs(1),
65+
r.UseClient(client),
66+
),
6367
Handler: func(inv *clibase.Invokation) error {
6468
user, err := client.User(inv.Context(), inv.Args[0])
6569
if err != nil {
@@ -108,7 +112,7 @@ func (*userShowFormat) ID() string {
108112
}
109113

110114
// AttachFlags implements OutputFormat.
111-
func (*userShowFormat) AttachFlags(_ *clibase.Cmd) {}
115+
func (*userShowFormat) AttachFlags(_ *pflag.FlagSet) {}
112116

113117
// Format implements OutputFormat.
114118
func (*userShowFormat) Format(_ context.Context, out interface{}) (string, error) {

cli/users.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ func (r *RootCmd) users() *clibase.Cmd {
1313
Handler: func(inv *clibase.Invokation) error {
1414
return inv.Command.HelpHandler(inv)
1515
},
16+
Children: []*clibase.Cmd{
17+
r.userCreate(),
18+
r.userList(),
19+
r.userSingle(),
20+
r.createUserStatusCommand(codersdk.UserStatusActive),
21+
r.createUserStatusCommand(codersdk.UserStatusSuspended),
22+
},
1623
}
17-
cmd.AddCommand(
18-
userCreate(),
19-
userList(),
20-
userSingle(),
21-
createUserStatusCommand(codersdk.UserStatusActive),
22-
createUserStatusCommand(codersdk.UserStatusSuspended),
23-
)
2424
return cmd
2525
}

cli/userstatus.go

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

33
import (
44
"fmt"
5+
"strings"
56

67
"golang.org/x/xerrors"
78

@@ -11,7 +12,7 @@ import (
1112
)
1213

1314
// createUserStatusCommand sets a user status.
14-
func createUserStatusCommand(sdkStatus codersdk.UserStatus) *clibase.Cmd {
15+
func (r *RootCmd) createUserStatusCommand(sdkStatus codersdk.UserStatus) *clibase.Cmd {
1516
var verb string
1617
var pastVerb string
1718
var aliases []string
@@ -31,18 +32,22 @@ func createUserStatusCommand(sdkStatus codersdk.UserStatus) *clibase.Cmd {
3132
panic(fmt.Sprintf("%s is not supported", sdkStatus))
3233
}
3334

35+
client := new(codersdk.Client)
36+
3437
var columns []string
3538
cmd := &clibase.Cmd{
36-
Use: fmt.Sprintf("%s <username|user_id>", verb),
37-
Short: short,
38-
Middleware: clibase.RequireNArgs(1),
39-
Aliases: aliases,
39+
Use: fmt.Sprintf("%s <username|user_id>", verb),
40+
Short: short,
41+
Aliases: aliases,
4042
Long: formatExamples(
4143
example{
4244
Command: fmt.Sprintf("coder users %s example_user", verb),
4345
},
4446
),
45-
Middleware: clibase.Chain(r.UseClient(client)),
47+
Middleware: clibase.Chain(
48+
clibase.RequireNArgs(1),
49+
r.UseClient(client),
50+
),
4651
Handler: func(inv *clibase.Invokation) error {
4752
identifier := inv.Args[0]
4853
if identifier == "" {
@@ -88,7 +93,14 @@ func createUserStatusCommand(sdkStatus codersdk.UserStatus) *clibase.Cmd {
8893
return nil
8994
},
9095
}
91-
cmd.Flags().StringArrayVarP(&columns, "column", "c", []string{"username", "email", "created_at", "status"},
92-
"Specify a column to filter in the table.")
96+
cmd.Options = clibase.OptionSet{
97+
{
98+
Flag: "column",
99+
FlagShorthand: "c",
100+
Description: "Specify a column to filter in the table.",
101+
Default: strings.Join([]string{"username", "email", "created_at", "status"}, ","),
102+
Value: clibase.StringsOf(&columns),
103+
},
104+
}
93105
return cmd
94106
}

0 commit comments

Comments
 (0)