Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

Commitfc3336c

Browse files
committed
Option to list all workspaces
From an admin POV, this will be helpful for various reasons.
1 parent3ebd102 commitfc3336c

File tree

3 files changed

+47
-7
lines changed

3 files changed

+47
-7
lines changed

‎internal/cmd/ceapi.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,13 @@ func getWorkspacesByProvider(ctx context.Context, client coder.Client, wpName, u
215215
returnnil,err
216216
}
217217

218-
workspaces,err=filterWorkspacesByUser(ctx,client,userEmail,workspaces)
219-
iferr!=nil {
220-
returnnil,err
218+
ifuserEmail!="" {
219+
workspaces,err=filterWorkspacesByUser(ctx,client,userEmail,workspaces)
220+
iferr!=nil {
221+
returnnil,err
222+
}
221223
}
224+
222225
returnworkspaces,nil
223226
}
224227

‎internal/cmd/workspaces.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ const (
7070

7171
funclsWorkspacesCommand()*cobra.Command {
7272
var (
73+
allbool
7374
outputFmtstring
7475
userstring
7576
providerstring
@@ -85,11 +86,18 @@ func lsWorkspacesCommand() *cobra.Command {
8586
iferr!=nil {
8687
returnerr
8788
}
88-
workspaces,err:=getWorkspaces(ctx,client,user)
89-
iferr!=nil {
90-
returnerr
89+
varworkspaces []coder.Workspace
90+
if!all {
91+
varerrerror
92+
workspaces,err=getWorkspaces(ctx,client,user)
93+
iferr!=nil {
94+
returnerr
95+
}
96+
}else {
97+
// If the user gave the all flag, then filtering by user doesn't make sense.
98+
user=""
9199
}
92-
ifprovider!="" {
100+
ifprovider!=""||all{
93101
workspaces,err=getWorkspacesByProvider(ctx,client,provider,user)
94102
iferr!=nil {
95103
returnerr
@@ -124,6 +132,7 @@ func lsWorkspacesCommand() *cobra.Command {
124132
},
125133
}
126134

135+
cmd.Flags().BoolVar(&all,"all",false,"Get workspaces for all users")
127136
cmd.Flags().StringVar(&user,"user",coder.Me,"Specify the user whose resources to target")
128137
cmd.Flags().StringVarP(&outputFmt,"output","o",humanOutput,"human | json")
129138
cmd.Flags().StringVarP(&provider,"provider","p","","Filter workspaces by a particular workspace provider name.")

‎internal/cmd/workspaces_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,34 @@ func Test_workspaces_ls(t *testing.T) {
2929
res.stdoutUnmarshals(t,&workspaces)
3030
}
3131

32+
funcTest_workspaces_ls_all(t*testing.T) {
33+
skipIfNoAuth(t)
34+
for_,test:=range []struct {
35+
namestring
36+
command []string
37+
assertfunc(rresult)
38+
}{
39+
{
40+
name:"simple list",
41+
command: []string{"workspaces","ls","--all"},
42+
assert:func(rresult) {r.success(t) },
43+
},
44+
{
45+
name:"list as json",
46+
command: []string{"workspaces","ls","--all","--output","json"},
47+
assert:func(rresult) {
48+
varworkspaces []coder.Workspace
49+
r.stdoutUnmarshals(t,&workspaces)
50+
},
51+
},
52+
} {
53+
test:=test
54+
t.Run(test.name,func(t*testing.T) {
55+
test.assert(execute(t,nil,test.command...))
56+
})
57+
}
58+
}
59+
3260
funcTest_workspaces_ls_by_provider(t*testing.T) {
3361
skipIfNoAuth(t)
3462
for_,test:=range []struct {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp