Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit e670978

Browse files
committed
Fixes
1 parent 36ececb commit e670978

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

internal/cmd/ceapi.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ func lookupUserOrgs(user *coder.User, orgs []coder.Organization) []coder.Organiz
3232
return userOrgs
3333
}
3434

35+
// getAllWorkspaces gets all workspaces for all users, on all providers.
36+
func getAllWorkspaces(ctx context.Context, client coder.Client) ([]coder.Workspace, error) {
37+
return client.Workspaces(ctx)
38+
}
39+
3540
// getWorkspaces returns all workspaces for the user.
3641
func getWorkspaces(ctx context.Context, client coder.Client, email string) ([]coder.Workspace, error) {
3742
user, err := client.UserByEmail(ctx, email)
@@ -215,13 +220,10 @@ func getWorkspacesByProvider(ctx context.Context, client coder.Client, wpName, u
215220
return nil, err
216221
}
217222

218-
if userEmail != "" {
219-
workspaces, err = filterWorkspacesByUser(ctx, client, userEmail, workspaces)
220-
if err != nil {
221-
return nil, err
222-
}
223+
workspaces, err = filterWorkspacesByUser(ctx, client, userEmail, workspaces)
224+
if err != nil {
225+
return nil, err
223226
}
224-
225227
return workspaces, nil
226228
}
227229

internal/cmd/workspaces.go

+10-7
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,24 @@ func lsWorkspacesCommand() *cobra.Command {
8787
return err
8888
}
8989
var workspaces []coder.Workspace
90-
if !all {
90+
if all {
9191
var err error
92-
workspaces, err = getWorkspaces(ctx, client, user)
92+
workspaces, err = getAllWorkspaces(ctx, client)
9393
if err != nil {
9494
return err
9595
}
96-
} else {
97-
// If the user gave the all flag, then filtering by user doesn't make sense.
98-
user = ""
99-
}
100-
if provider != "" || all {
96+
} else if provider != "" {
97+
var err error
10198
workspaces, err = getWorkspacesByProvider(ctx, client, provider, user)
10299
if err != nil {
103100
return err
104101
}
102+
} else {
103+
var err error
104+
workspaces, err = getWorkspaces(ctx, client, user)
105+
if err != nil {
106+
return err
107+
}
105108
}
106109
if len(workspaces) < 1 {
107110
clog.LogInfo("no workspaces found")

0 commit comments

Comments
 (0)