Skip to content

Commit f82a755

Browse files
committed
Fix CLI usages
1 parent 1d59a44 commit f82a755

11 files changed

+19
-82
lines changed

cli/autostart.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,8 @@ func autostartShow() *cobra.Command {
4141
if err != nil {
4242
return err
4343
}
44-
organization, err := currentOrganization(cmd, client)
45-
if err != nil {
46-
return err
47-
}
4844

49-
workspace, err := client.WorkspaceByOwnerAndName(cmd.Context(), organization.ID, codersdk.Me, args[0])
45+
workspace, err := client.WorkspaceByOwnerAndName(cmd.Context(), codersdk.Me, args[0])
5046
if err != nil {
5147
return err
5248
}
@@ -93,18 +89,14 @@ func autostartEnable() *cobra.Command {
9389
if err != nil {
9490
return err
9591
}
96-
organization, err := currentOrganization(cmd, client)
97-
if err != nil {
98-
return err
99-
}
10092

10193
spec := fmt.Sprintf("CRON_TZ=%s %s %s * * %s", autostartTimezone, autostartMinute, autostartHour, autostartDayOfWeek)
10294
validSchedule, err := schedule.Weekly(spec)
10395
if err != nil {
10496
return err
10597
}
10698

107-
workspace, err := client.WorkspaceByOwnerAndName(cmd.Context(), organization.ID, codersdk.Me, args[0])
99+
workspace, err := client.WorkspaceByOwnerAndName(cmd.Context(), codersdk.Me, args[0])
108100
if err != nil {
109101
return err
110102
}
@@ -142,12 +134,8 @@ func autostartDisable() *cobra.Command {
142134
if err != nil {
143135
return err
144136
}
145-
organization, err := currentOrganization(cmd, client)
146-
if err != nil {
147-
return err
148-
}
149137

150-
workspace, err := client.WorkspaceByOwnerAndName(cmd.Context(), organization.ID, codersdk.Me, args[0])
138+
workspace, err := client.WorkspaceByOwnerAndName(cmd.Context(), codersdk.Me, args[0])
151139
if err != nil {
152140
return err
153141
}

cli/bump.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,7 @@ func bump() *cobra.Command {
4343
if err != nil {
4444
return xerrors.Errorf("create client: %w", err)
4545
}
46-
organization, err := currentOrganization(cmd, client)
47-
if err != nil {
48-
return xerrors.Errorf("get current org: %w", err)
49-
}
50-
51-
workspace, err := client.WorkspaceByOwnerAndName(cmd.Context(), organization.ID, codersdk.Me, args[0])
46+
workspace, err := client.WorkspaceByOwnerAndName(cmd.Context(), codersdk.Me, args[0])
5247
if err != nil {
5348
return xerrors.Errorf("get workspace: %w", err)
5449
}

cli/create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func create() *cobra.Command {
4949
workspaceName, err = cliui.Prompt(cmd, cliui.PromptOptions{
5050
Text: "Specify a name for your workspace:",
5151
Validate: func(workspaceName string) error {
52-
_, err = client.WorkspaceByOwnerAndName(cmd.Context(), organization.ID, codersdk.Me, workspaceName)
52+
_, err = client.WorkspaceByOwnerAndName(cmd.Context(), codersdk.Me, workspaceName)
5353
if err == nil {
5454
return xerrors.Errorf("A workspace already exists named %q!", workspaceName)
5555
}
@@ -75,7 +75,7 @@ func create() *cobra.Command {
7575
return xerrors.Errorf("TTL must be at least 1 minute")
7676
}
7777

78-
_, err = client.WorkspaceByOwnerAndName(cmd.Context(), organization.ID, codersdk.Me, workspaceName)
78+
_, err = client.WorkspaceByOwnerAndName(cmd.Context(), codersdk.Me, workspaceName)
7979
if err == nil {
8080
return xerrors.Errorf("A workspace already exists named %q!", workspaceName)
8181
}

cli/portforward.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,8 @@ func portForward() *cobra.Command {
7070
if err != nil {
7171
return err
7272
}
73-
organization, err := currentOrganization(cmd, client)
74-
if err != nil {
75-
return err
76-
}
7773

78-
workspace, agent, err := getWorkspaceAndAgent(cmd, client, organization.ID, codersdk.Me, args[0], false)
74+
workspace, agent, err := getWorkspaceAndAgent(cmd, client, codersdk.Me, args[0], false)
7975
if err != nil {
8076
return err
8177
}

cli/show.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ func show() *cobra.Command {
1919
if err != nil {
2020
return err
2121
}
22-
organization, err := currentOrganization(cmd, client)
23-
if err != nil {
24-
return err
25-
}
26-
workspace, err := client.WorkspaceByOwnerAndName(cmd.Context(), organization.ID, codersdk.Me, args[0])
22+
workspace, err := client.WorkspaceByOwnerAndName(cmd.Context(), codersdk.Me, args[0])
2723
if err != nil {
2824
return xerrors.Errorf("get workspace: %w", err)
2925
}

cli/ssh.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ func ssh() *cobra.Command {
4848
if err != nil {
4949
return err
5050
}
51-
organization, err := currentOrganization(cmd, client)
52-
if err != nil {
53-
return err
54-
}
5551

5652
if shuffle {
5753
err := cobra.ExactArgs(0)(cmd, args)
@@ -65,7 +61,7 @@ func ssh() *cobra.Command {
6561
}
6662
}
6763

68-
workspace, agent, err := getWorkspaceAndAgent(cmd, client, organization.ID, codersdk.Me, args[0], shuffle)
64+
workspace, agent, err := getWorkspaceAndAgent(cmd, client, codersdk.Me, args[0], shuffle)
6965
if err != nil {
7066
return err
7167
}
@@ -185,7 +181,7 @@ func ssh() *cobra.Command {
185181
// getWorkspaceAgent returns the workspace and agent selected using either the
186182
// `<workspace>[.<agent>]` syntax via `in` or picks a random workspace and agent
187183
// if `shuffle` is true.
188-
func getWorkspaceAndAgent(cmd *cobra.Command, client *codersdk.Client, orgID uuid.UUID, userID string, in string, shuffle bool) (codersdk.Workspace, codersdk.WorkspaceAgent, error) { //nolint:revive
184+
func getWorkspaceAndAgent(cmd *cobra.Command, client *codersdk.Client, userID string, in string, shuffle bool) (codersdk.Workspace, codersdk.WorkspaceAgent, error) { //nolint:revive
189185
ctx := cmd.Context()
190186

191187
var (
@@ -209,7 +205,7 @@ func getWorkspaceAndAgent(cmd *cobra.Command, client *codersdk.Client, orgID uui
209205
return codersdk.Workspace{}, codersdk.WorkspaceAgent{}, err
210206
}
211207
} else {
212-
workspace, err = client.WorkspaceByOwnerAndName(cmd.Context(), orgID, userID, workspaceParts[0])
208+
workspace, err = client.WorkspaceByOwnerAndName(cmd.Context(), userID, workspaceParts[0])
213209
if err != nil {
214210
return codersdk.Workspace{}, codersdk.WorkspaceAgent{}, err
215211
}

cli/start.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ func start() *cobra.Command {
2828
if err != nil {
2929
return err
3030
}
31-
organization, err := currentOrganization(cmd, client)
32-
if err != nil {
33-
return err
34-
}
35-
workspace, err := client.WorkspaceByOwnerAndName(cmd.Context(), organization.ID, codersdk.Me, args[0])
31+
workspace, err := client.WorkspaceByOwnerAndName(cmd.Context(), codersdk.Me, args[0])
3632
if err != nil {
3733
return err
3834
}

cli/state.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,7 @@ func statePull() *cobra.Command {
3030
if err != nil {
3131
return err
3232
}
33-
organization, err := currentOrganization(cmd, client)
34-
if err != nil {
35-
return err
36-
}
37-
38-
workspace, err := client.WorkspaceByOwnerAndName(cmd.Context(), organization.ID, codersdk.Me, args[0])
33+
workspace, err := client.WorkspaceByOwnerAndName(cmd.Context(), codersdk.Me, args[0])
3934
if err != nil {
4035
return err
4136
}
@@ -76,12 +71,7 @@ func statePush() *cobra.Command {
7671
if err != nil {
7772
return err
7873
}
79-
organization, err := currentOrganization(cmd, client)
80-
if err != nil {
81-
return err
82-
}
83-
84-
workspace, err := client.WorkspaceByOwnerAndName(cmd.Context(), organization.ID, codersdk.Me, args[0])
74+
workspace, err := client.WorkspaceByOwnerAndName(cmd.Context(), codersdk.Me, args[0])
8575
if err != nil {
8676
return err
8777
}

cli/stop.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ func stop() *cobra.Command {
2828
if err != nil {
2929
return err
3030
}
31-
organization, err := currentOrganization(cmd, client)
32-
if err != nil {
33-
return err
34-
}
35-
workspace, err := client.WorkspaceByOwnerAndName(cmd.Context(), organization.ID, codersdk.Me, args[0])
31+
workspace, err := client.WorkspaceByOwnerAndName(cmd.Context(), codersdk.Me, args[0])
3632
if err != nil {
3733
return err
3834
}

cli/ttl.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,8 @@ func ttlShow() *cobra.Command {
3939
if err != nil {
4040
return xerrors.Errorf("create client: %w", err)
4141
}
42-
organization, err := currentOrganization(cmd, client)
43-
if err != nil {
44-
return xerrors.Errorf("get current org: %w", err)
45-
}
4642

47-
workspace, err := client.WorkspaceByOwnerAndName(cmd.Context(), organization.ID, codersdk.Me, args[0])
43+
workspace, err := client.WorkspaceByOwnerAndName(cmd.Context(), codersdk.Me, args[0])
4844
if err != nil {
4945
return xerrors.Errorf("get workspace: %w", err)
5046
}
@@ -72,12 +68,8 @@ func ttlset() *cobra.Command {
7268
if err != nil {
7369
return xerrors.Errorf("create client: %w", err)
7470
}
75-
organization, err := currentOrganization(cmd, client)
76-
if err != nil {
77-
return xerrors.Errorf("get current org: %w", err)
78-
}
7971

80-
workspace, err := client.WorkspaceByOwnerAndName(cmd.Context(), organization.ID, codersdk.Me, args[0])
72+
workspace, err := client.WorkspaceByOwnerAndName(cmd.Context(), codersdk.Me, args[0])
8173
if err != nil {
8274
return xerrors.Errorf("get workspace: %w", err)
8375
}
@@ -120,12 +112,8 @@ func ttlunset() *cobra.Command {
120112
if err != nil {
121113
return xerrors.Errorf("create client: %w", err)
122114
}
123-
organization, err := currentOrganization(cmd, client)
124-
if err != nil {
125-
return xerrors.Errorf("get current org: %w", err)
126-
}
127115

128-
workspace, err := client.WorkspaceByOwnerAndName(cmd.Context(), organization.ID, codersdk.Me, args[0])
116+
workspace, err := client.WorkspaceByOwnerAndName(cmd.Context(), codersdk.Me, args[0])
129117
if err != nil {
130118
return xerrors.Errorf("get workspace: %w", err)
131119
}

cli/update.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ func update() *cobra.Command {
1919
if err != nil {
2020
return err
2121
}
22-
organization, err := currentOrganization(cmd, client)
23-
if err != nil {
24-
return err
25-
}
26-
workspace, err := client.WorkspaceByOwnerAndName(cmd.Context(), organization.ID, codersdk.Me, args[0])
22+
workspace, err := client.WorkspaceByOwnerAndName(cmd.Context(), codersdk.Me, args[0])
2723
if err != nil {
2824
return err
2925
}

0 commit comments

Comments
 (0)