feat: default the CLI workspace search to the user filter (#29753)

This commit is contained in:
McKayla はな
2026-09-23 19:42:10 -06:00
committed by GitHub
parent 569c612d4d
commit 0c98308ca9
9 changed files with 37 additions and 20 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ import (
"github.com/coder/serpent"
)
var defaultQuery = "owner:me"
var defaultQuery = "user:me"
// WorkspaceFilter wraps codersdk.WorkspaceFilter
// and allows easy integration to a CLI command.
+1 -1
View File
@@ -129,7 +129,7 @@ func (r *RootCmd) list() *serpent.Command {
workspaceFilter.SharedWithUser = user.ID.String()
// Unset the default query that conflicts with the --shared-with-me flag
if workspaceFilter.FilterQuery == "owner:me" {
if workspaceFilter.FilterQuery == "user:me" {
workspaceFilter.FilterQuery = ""
}
}
+20 -3
View File
@@ -127,24 +127,41 @@ func TestList(t *testing.T) {
ctx := testutil.Context(t, testutil.WaitMedium)
client.UpdateWorkspaceACL(ctx, sharedWorkspace.ID, codersdk.UpdateWorkspaceACL{
// Share orgOwner's workspace with member
err := client.UpdateWorkspaceACL(ctx, sharedWorkspace.ID, codersdk.UpdateWorkspaceACL{
UserRoles: map[string]codersdk.WorkspaceRole{
member.ID.String(): codersdk.WorkspaceRoleUse,
},
})
require.NoError(t, err)
inv, root := clitest.New(t, "list", "--shared-with-me", "--output=json")
// member should see the workspace with the default filter
inv, root := clitest.New(t, "list", "--output=json")
clitest.SetupConfig(t, memberClient, root)
stdout := new(bytes.Buffer)
inv.Stdout = stdout
err := inv.WithContext(ctx).Run()
err = inv.WithContext(ctx).Run()
require.NoError(t, err)
var workspaces []codersdk.Workspace
require.NoError(t, json.Unmarshal(stdout.Bytes(), &workspaces))
require.Len(t, workspaces, 1)
require.Equal(t, sharedWorkspace.ID, workspaces[0].ID)
// member should see the workspace when passing `--shared-with-me`
inv, root = clitest.New(t, "list", "--shared-with-me", "--output=json")
clitest.SetupConfig(t, memberClient, root)
stdout = new(bytes.Buffer)
inv.Stdout = stdout
err = inv.WithContext(ctx).Run()
require.NoError(t, err)
workspaces = nil
require.NoError(t, json.Unmarshal(stdout.Bytes(), &workspaces))
require.Len(t, workspaces, 1)
require.Equal(t, sharedWorkspace.ID, workspaces[0].ID)
})
t.Run("HTMLResponse", func(t *testing.T) {
+1 -1
View File
@@ -17,7 +17,7 @@ OPTIONS:
-o, --output table|json (default: table)
Output format.
--search string (default: owner:me)
--search string (default: user:me)
Search for a workspace with a query.
———
+1 -1
View File
@@ -21,7 +21,7 @@ OPTIONS:
-o, --output table|json (default: table)
Output format.
--search string (default: owner:me)
--search string (default: user:me)
Search for a workspace with a query.
———
+4 -4
View File
@@ -30,10 +30,10 @@ Specifies whether all workspaces will be listed or not.
### --search
| | |
|---------|-----------------------|
| Type | <code>string</code> |
| Default | <code>owner:me</code> |
| | |
|---------|----------------------|
| Type | <code>string</code> |
| Default | <code>user:me</code> |
Search for a workspace with a query.
+4 -4
View File
@@ -30,10 +30,10 @@ Specifies whether all workspaces will be listed or not.
### --search
| | |
|---------|-----------------------|
| Type | <code>string</code> |
| Default | <code>owner:me</code> |
| | |
|---------|----------------------|
| Type | <code>string</code> |
| Default | <code>user:me</code> |
Search for a workspace with a query.
+4 -4
View File
@@ -37,10 +37,10 @@ Specifies whether all workspaces will be listed or not.
### --search
| | |
|---------|-----------------------|
| Type | <code>string</code> |
| Default | <code>owner:me</code> |
| | |
|---------|----------------------|
| Type | <code>string</code> |
| Default | <code>user:me</code> |
Search for a workspace with a query.
@@ -17,7 +17,7 @@ OPTIONS:
-o, --output table|json (default: table)
Output format.
--search string (default: owner:me)
--search string (default: user:me)
Search for a workspace with a query.
———