-
Notifications
You must be signed in to change notification settings - Fork 19
feat: Option to list all workspaces #416
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,6 +70,7 @@ const ( | |
|
|
||
| func lsWorkspacesCommand() *cobra.Command { | ||
| var ( | ||
| all bool | ||
| outputFmt string | ||
| user string | ||
| provider string | ||
|
|
@@ -85,11 +86,18 @@ func lsWorkspacesCommand() *cobra.Command { | |
| if err != nil { | ||
| return err | ||
| } | ||
| workspaces, err := getWorkspaces(ctx, client, user) | ||
| if err != nil { | ||
| return err | ||
| var workspaces []coder.Workspace | ||
| if !all { | ||
| var err error | ||
| workspaces, err = getWorkspaces(ctx, client, user) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } else { | ||
| // If the user gave the all flag, then filtering by user doesn't make sense. | ||
| user = "" | ||
| } | ||
| if provider != "" { | ||
| if provider != "" || all { | ||
|
||
| workspaces, err = getWorkspacesByProvider(ctx, client, provider, user) | ||
| if err != nil { | ||
| return err | ||
|
|
@@ -124,6 +132,7 @@ func lsWorkspacesCommand() *cobra.Command { | |
| }, | ||
| } | ||
|
|
||
| cmd.Flags().BoolVar(&all, "all", false, "Get workspaces for all users") | ||
goodspark marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| cmd.Flags().StringVar(&user, "user", coder.Me, "Specify the user whose resources to target") | ||
| cmd.Flags().StringVarP(&outputFmt, "output", "o", humanOutput, "human | json") | ||
| cmd.Flags().StringVarP(&provider, "provider", "p", "", "Filter workspaces by a particular workspace provider name.") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,34 @@ func Test_workspaces_ls(t *testing.T) { | |
| res.stdoutUnmarshals(t, &workspaces) | ||
| } | ||
|
|
||
| func Test_workspaces_ls_all(t *testing.T) { | ||
| skipIfNoAuth(t) | ||
| for _, test := range []struct { | ||
| name string | ||
| command []string | ||
| assert func(r result) | ||
| }{ | ||
| { | ||
| name: "simple list", | ||
| command: []string{"workspaces", "ls", "--all"}, | ||
deansheather marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assert: func(r result) { r.success(t) }, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sanity check: This isn't actually checking the output - just that the command exited with 0?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Essentially, yeah. This mini test framework "runs" the commands in-process and checks if the command fn returned an error. |
||
| }, | ||
| { | ||
| name: "list as json", | ||
| command: []string{"workspaces", "ls", "--all", "--output", "json"}, | ||
| assert: func(r result) { | ||
| var workspaces []coder.Workspace | ||
| r.stdoutUnmarshals(t, &workspaces) | ||
| }, | ||
| }, | ||
| } { | ||
| test := test | ||
| t.Run(test.name, func(t *testing.T) { | ||
| test.assert(execute(t, nil, test.command...)) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func Test_workspaces_ls_by_provider(t *testing.T) { | ||
| skipIfNoAuth(t) | ||
| for _, test := range []struct { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't need the
var errs here or in the other if branches since it's already defined above, then you can condense theif errcheck to be underneath the if branches, so each branch is just theworkspaces, err = getX()statement.edit: check my suggestion