Skip to content

Commit eeb9500

Browse files
committed
576 problems remaining...
All useclients
1 parent 6fb72b5 commit eeb9500

20 files changed

+120
-136
lines changed

cli/delete.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@ import (
1212
// nolint
1313
func (r *RootCmd) deleteWorkspace() *clibase.Cmd {
1414
var orphan bool
15+
var client *codersdk.Client
1516
cmd := &clibase.Cmd{
1617
Annotations: workspaceCommand,
1718
Use: "delete <workspace>",
1819
Short: "Delete a workspace",
1920
Aliases: []string{"rm"},
20-
Middleware: clibase.RequireNArgs(1),
21+
Middleware: clibase.Chain(
22+
clibase.RequireNArgs(1),
23+
r.useClient(client),
24+
),
2125
Handler: func(inv *clibase.Invokation) error {
2226
_, err := cliui.Prompt(inv, cliui.PromptOptions{
2327
Text: "Confirm delete workspace?",
@@ -28,10 +32,6 @@ func (r *RootCmd) deleteWorkspace() *clibase.Cmd {
2832
return err
2933
}
3034

31-
client, err := useClient(cmd)
32-
if err != nil {
33-
return err
34-
}
3535
workspace, err := namedWorkspace(inv.Context(), client, inv.Args[0])
3636
if err != nil {
3737
return err

cli/login.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414

1515
"github.com/go-playground/validator/v10"
1616
"github.com/pkg/browser"
17-
"github.com/spf13/cobra"
1817
"golang.org/x/xerrors"
1918

2019
"github.com/coder/coder/cli/clibase"
@@ -51,7 +50,7 @@ func (r *RootCmd) login() *clibase.Cmd {
5150
cmd := &clibase.Cmd{
5251
Use: "login <url>",
5352
Short: "Authenticate with Coder deployment",
54-
Args: cobra.MaximumNArgs(1),
53+
Args: clibase.RequireRangeArgs(0,1),
5554
Handler: func(inv *clibase.Invokation) error {
5655
rawURL := ""
5756
if len(inv.Args) == 0 {

cli/parameterslist.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ func (r *RootCmd) parameterList() *clibase.Cmd {
1717
cliui.JSONFormat(),
1818
)
1919

20+
var client *codersdk.Client
21+
2022
cmd := &clibase.Cmd{
21-
Use: "list",
22-
Aliases: []string{"ls"},
23-
Middleware: clibase.RequireNArgs(2),
23+
Use: "list",
24+
Aliases: []string{"ls"},
25+
Middleware: clibase.Chain(
26+
clibase.RequireNArgs(2),
27+
r.useClient(client),
28+
),
2429
Handler: func(inv *clibase.Invokation) error {
2530
scope, name := inv.Args[0], inv.Args[1]
2631

27-
client, err := useClient(cmd)
28-
if err != nil {
29-
return err
30-
}
31-
3232
organization, err := CurrentOrganization(inv, client)
3333
if err != nil {
3434
return xerrors.Errorf("get current organization: %w", err)

cli/ping.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ func (r *RootCmd) ping() *clibase.Cmd {
2222
pingWait time.Duration
2323
verbose bool
2424
)
25+
26+
var client *codersdk.Client
2527
cmd := &clibase.Cmd{
2628
Annotations: workspaceCommand,
2729
Use: "ping <workspace>",
2830
Short: "Ping a workspace",
29-
Middleware: clibase.RequireNArgs(1),
31+
Middleware: clibase.Chain(
32+
clibase.RequireNArgs(1),
33+
r.useClient(client),
34+
),
3035
Handler: func(inv *clibase.Invokation) error {
3136
ctx, cancel := context.WithCancel(inv.Context())
3237
defer cancel()
3338

34-
client, err := useClient(cmd)
35-
if err != nil {
36-
return err
37-
}
38-
3939
workspaceName := inv.Args[0]
4040
_, workspaceAgent, err := getWorkspaceAndAgent(ctx, cmd, client, codersdk.Me, workspaceName, false)
4141
if err != nil {

cli/portforward.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ func (r *RootCmd) portForward() *clibase.Cmd {
2626
tcpForwards []string // <port>:<port>
2727
udpForwards []string // <port>:<port>
2828
)
29+
var client *codersdk.Client
2930
cmd := &clibase.Cmd{
30-
Use: "port-forward <workspace>",
31-
Short: "Forward ports from machine to a workspace",
32-
Aliases: []string{"tunnel"},
33-
Middleware: clibase.RequireNArgs(1),
31+
Use: "port-forward <workspace>",
32+
Short: "Forward ports from machine to a workspace",
33+
Aliases: []string{"tunnel"},
3434
Long: formatExamples(
3535
example{
3636
Description: "Port forward a single TCP port from 1234 in the workspace to port 5678 on your local machine",
@@ -49,6 +49,10 @@ func (r *RootCmd) portForward() *clibase.Cmd {
4949
Command: "coder port-forward <workspace> --tcp 8080,9000:3000,9090-9092,10000-10002:10010-10012",
5050
},
5151
),
52+
Middleware: clibase.Chain(
53+
clibase.RequireNArgs(1),
54+
r.useClient(client),
55+
),
5256
Handler: func(inv *clibase.Invokation) error {
5357
ctx, cancel := context.WithCancel(inv.Context())
5458
defer cancel()
@@ -65,11 +69,6 @@ func (r *RootCmd) portForward() *clibase.Cmd {
6569
return xerrors.New("no port-forwards requested")
6670
}
6771

68-
client, err := useClient(cmd)
69-
if err != nil {
70-
return err
71-
}
72-
7372
workspace, workspaceAgent, err := getWorkspaceAndAgent(ctx, cmd, client, codersdk.Me, inv.Args[0], false)
7473
if err != nil {
7574
return err

cli/publickey.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,13 @@ import (
1212

1313
func (r *RootCmd) publickey() *clibase.Cmd {
1414
var reset bool
15-
15+
var client *codersdk.Client
1616
cmd := &clibase.Cmd{
17-
Use: "publickey",
18-
Aliases: []string{"pubkey"},
19-
Short: "Output your Coder public key used for Git operations",
17+
Use: "publickey",
18+
Aliases: []string{"pubkey"},
19+
Short: "Output your Coder public key used for Git operations",
20+
Middleware: r.useClient(client),
2021
Handler: func(inv *clibase.Invokation) error {
21-
client, err := useClient(cmd)
22-
if err != nil {
23-
return xerrors.Errorf("create codersdk client: %w", err)
24-
}
25-
2622
if reset {
2723
// Confirm prompt if using --reset. We don't want to accidentally
2824
// reset our public key.

cli/restart.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ import (
1010
)
1111

1212
func (r *RootCmd) restart() *clibase.Cmd {
13+
var client *codersdk.Client
1314
cmd := &clibase.Cmd{
1415
Annotations: workspaceCommand,
1516
Use: "restart <workspace>",
1617
Short: "Restart a workspace",
17-
Middleware: clibase.RequireNArgs(1),
18+
Middleware: clibase.Chain(
19+
clibase.RequireNArgs(1),
20+
r.useClient(client),
21+
),
1822
Handler: func(inv *clibase.Invokation) error {
1923
ctx := inv.Context()
2024
out := inv.Stdout
@@ -27,10 +31,6 @@ func (r *RootCmd) restart() *clibase.Cmd {
2731
return err
2832
}
2933

30-
client, err := useClient(cmd)
31-
if err != nil {
32-
return err
33-
}
3434
workspace, err := namedWorkspace(inv.Context(), client, inv.Args[0])
3535
if err != nil {
3636
return err

cli/scaletest.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -310,19 +310,19 @@ func (r *userCleanupRunner) Run(ctx context.Context, _ string, _ io.Writer) erro
310310

311311
func (r *RootCmd) scaletestCleanup() *clibase.Cmd {
312312
cleanupStrategy := &scaletestStrategyFlags{cleanup: true}
313+
var client *codersdk.Client
313314

314315
cmd := &clibase.Cmd{
315316
Use: "cleanup",
316317
Short: "Cleanup any orphaned scaletest resources",
317318
Long: "Cleanup scaletest workspaces, then cleanup scaletest users. The strategy flags will apply to each stage of the cleanup process.",
319+
Middleware: clibase.Chain(
320+
r.useClient(client),
321+
),
318322
Handler: func(inv *clibase.Invokation) error {
319323
ctx := inv.Context()
320-
client, err := useClient(cmd)
321-
if err != nil {
322-
return err
323-
}
324324

325-
_, err = requireAdmin(ctx, client)
325+
_, err := requireAdmin(ctx, client)
326326
if err != nil {
327327
return err
328328
}
@@ -494,18 +494,17 @@ func (r *RootCmd) scaletestCreateWorkspaces() *clibase.Cmd {
494494
output = &scaletestOutputFlags{}
495495
)
496496

497+
var client *codersdk.Client
498+
497499
cmd := &clibase.Cmd{
498500
Use: "create-workspaces",
499501
Short: "Creates many workspaces and waits for them to be ready",
500502
Long: `Creates many users, then creates a workspace for each user and waits for them finish building and fully come online. Optionally runs a command inside each workspace, and connects to the workspace over WireGuard.
501503
502504
It is recommended that all rate limits are disabled on the server before running this scaletest. This test generates many login events which will be rate limited against the (most likely single) IP.`,
505+
Middleware: r.useClient(client),
503506
Handler: func(inv *clibase.Invokation) error {
504507
ctx := inv.Context()
505-
client, err := useClient(cmd)
506-
if err != nil {
507-
return err
508-
}
509508

510509
me, err := requireAdmin(ctx, client)
511510
if err != nil {

cli/schedule.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,27 +185,25 @@ func (r *RootCmd) scheduleStop() *clibase.Cmd {
185185
}
186186

187187
func (r *RootCmd) scheduleOverride() *clibase.Cmd {
188+
var client *codersdk.Client
188189
overrideCmd := &clibase.Cmd{
189-
Middleware: clibase.RequireNArgs(2),
190-
Use: "override-stop <workspace-name> <duration from now>",
191-
Long: formatExamples(
190+
Use: "override-stop <workspace-name> <duration from now>",
191+
Short: "Edit stop time of active workspace",
192+
Long: scheduleOverrideDescriptionLong + "\n" + formatExamples(
192193
example{
193194
Command: "coder schedule override-stop my-workspace 90m",
194195
},
195196
),
196-
Short: "Edit stop time of active workspace",
197-
Long: scheduleOverrideDescriptionLong,
197+
Middleware: clibase.Chain(
198+
clibase.RequireNArgs(2),
199+
r.useClient(client),
200+
),
198201
Handler: func(inv *clibase.Invokation) error {
199202
overrideDuration, err := parseDuration(inv.Args[1])
200203
if err != nil {
201204
return err
202205
}
203206

204-
client, err := useClient(cmd)
205-
if err != nil {
206-
return xerrors.Errorf("create client: %w", err)
207-
}
208-
209207
workspace, err := namedWorkspace(inv.Context(), client, inv.Args[0])
210208
if err != nil {
211209
return xerrors.Errorf("get workspace: %w", err)

cli/speedtest.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,19 @@ func (r *RootCmd) speedtest() *clibase.Cmd {
2323
duration time.Duration
2424
direction string
2525
)
26+
var client *codersdk.Client
2627
cmd := &clibase.Cmd{
2728
Annotations: workspaceCommand,
2829
Use: "speedtest <workspace>",
29-
Middleware: clibase.RequireNArgs(1),
3030
Short: "Run upload and download tests from your machine to a workspace",
31+
Middleware: clibase.Chain(
32+
clibase.RequireNArgs(1),
33+
r.useClient(client),
34+
),
3135
Handler: func(inv *clibase.Invokation) error {
3236
ctx, cancel := context.WithCancel(inv.Context())
3337
defer cancel()
3438

35-
client, err := useClient(cmd)
36-
if err != nil {
37-
return xerrors.Errorf("create codersdk client: %w", err)
38-
}
39-
4039
workspace, workspaceAgent, err := getWorkspaceAndAgent(ctx, cmd, client, codersdk.Me, inv.Args[0], false)
4140
if err != nil {
4241
return err

0 commit comments

Comments
 (0)