MCPcopy Index your code
hub / github.com/coder/coder / QueryConvertWorkspaces

Function QueryConvertWorkspaces

cli/list.go:169–180  ·  view source on GitHub ↗

queryConvertWorkspaces is a helper function for converting codersdk.Workspaces to a different type. It's used by the list command to convert workspaces to WorkspaceListRow, and by the schedule command to convert workspaces to scheduleListRow.

(ctx context.Context, client *codersdk.Client, filter codersdk.WorkspaceFilter, convertF func(time.Time, codersdk.Workspace) T)

Source from the content-addressed store, hash-verified

167// WorkspaceListRow, and by the schedule command to
168// convert workspaces to scheduleListRow.
169func QueryConvertWorkspaces[T any](ctx context.Context, client *codersdk.Client, filter codersdk.WorkspaceFilter, convertF func(time.Time, codersdk.Workspace) T) ([]T, error) {
170 var empty []T
171 workspaces, err := client.Workspaces(ctx, filter)
172 if err != nil {
173 return empty, xerrors.Errorf("query workspaces: %w", err)
174 }
175 converted := make([]T, len(workspaces.Workspaces))
176 for i, workspace := range workspaces.Workspaces {
177 converted[i] = convertF(time.Now(), workspace)
178 }
179 return converted, nil
180}

Callers 2

scheduleShowMethod · 0.85
listMethod · 0.85

Calls 2

WorkspacesMethod · 0.80
ErrorfMethod · 0.45

Tested by

no test coverage detected