Skip to content

feat: Support search query and --me in workspace list #3667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions cli/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ func workspaceListRowFromWorkspace(now time.Time, usersByID map[uuid.UUID]coders
}

func list() *cobra.Command {
var columns []string
var (
columns []string
searchQuery string
me bool
)
cmd := &cobra.Command{
Annotations: workspaceCommand,
Use: "list",
Expand All @@ -69,7 +73,17 @@ func list() *cobra.Command {
if err != nil {
return err
}
workspaces, err := client.Workspaces(cmd.Context(), codersdk.WorkspaceFilter{})
filter := codersdk.WorkspaceFilter{
FilterQuery: searchQuery,
}
if me {
myUser, err := client.User(cmd.Context(), codersdk.Me)
if err != nil {
return err
}
filter.Owner = myUser.Username
}
workspaces, err := client.Workspaces(cmd.Context(), filter)
if err != nil {
return err
}
Expand Down Expand Up @@ -106,5 +120,7 @@ func list() *cobra.Command {
}
cmd.Flags().StringArrayVarP(&columns, "column", "c", nil,
"Specify a column to filter in the table.")
cmd.Flags().StringVar(&searchQuery, "search", "", "Search for a workspace with a query.")
cmd.Flags().BoolVar(&me, "me", false, "Only show workspaces owned by the current user.")
return cmd
}