Stacked on #29913. Now that `ResolveWorkspace` forwards `WorkspaceOptions`, narrows the related data loaded by three CLI commands that only use the workspace's own `ID` and `Name`. Each passes an empty `wsrelated.Config{}` so the server skips loading the template and latest build. - `cli/favorite.go`: `favorite` and `unfavorite`. - `cli/autoupdate.go`: `autoupdate`. - `cli/rename.go`: `rename`. These were selected as the safest first candidates: they read only core workspace fields, so no output or behavior changes, only the amount of data fetched. _This PR was created by Coder Agents on behalf of @spikecurtis._
74 lines
2.0 KiB
Go
74 lines
2.0 KiB
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
"github.com/coder/coder/v2/codersdk"
|
|
"github.com/coder/coder/v2/codersdk/wsrelated"
|
|
"github.com/coder/serpent"
|
|
)
|
|
|
|
func (r *RootCmd) favorite() *serpent.Command {
|
|
cmd := &serpent.Command{
|
|
Aliases: []string{"fav", "favou" + "rite"},
|
|
Annotations: workspaceCommand,
|
|
Use: "favorite <workspace>",
|
|
Short: "Add a workspace to your favorites",
|
|
Middleware: serpent.Chain(
|
|
serpent.RequireNArgs(1),
|
|
),
|
|
Handler: func(inv *serpent.Invocation) error {
|
|
client, err := r.InitClient(inv)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Only the workspace ID and name are used.
|
|
ws, err := client.ResolveWorkspace(inv.Context(), inv.Args[0], codersdk.WorkspaceOptions{IncludeRelated: &wsrelated.Config{}})
|
|
if err != nil {
|
|
return xerrors.Errorf("get workspace: %w", err)
|
|
}
|
|
|
|
if err := client.FavoriteWorkspace(inv.Context(), ws.ID); err != nil {
|
|
return xerrors.Errorf("favorite workspace: %w", err)
|
|
}
|
|
_, _ = fmt.Fprintf(inv.Stdout, "Workspace %q added to favorites.\n", ws.Name)
|
|
return nil
|
|
},
|
|
}
|
|
return cmd
|
|
}
|
|
|
|
func (r *RootCmd) unfavorite() *serpent.Command {
|
|
cmd := &serpent.Command{
|
|
Aliases: []string{"unfav", "unfavou" + "rite"},
|
|
Annotations: workspaceCommand,
|
|
Use: "unfavorite <workspace>",
|
|
Short: "Remove a workspace from your favorites",
|
|
Middleware: serpent.Chain(
|
|
serpent.RequireNArgs(1),
|
|
),
|
|
Handler: func(inv *serpent.Invocation) error {
|
|
client, err := r.InitClient(inv)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Only the workspace ID and name are used.
|
|
ws, err := client.ResolveWorkspace(inv.Context(), inv.Args[0], codersdk.WorkspaceOptions{IncludeRelated: &wsrelated.Config{}})
|
|
if err != nil {
|
|
return xerrors.Errorf("get workspace: %w", err)
|
|
}
|
|
|
|
if err := client.UnfavoriteWorkspace(inv.Context(), ws.ID); err != nil {
|
|
return xerrors.Errorf("unfavorite workspace: %w", err)
|
|
}
|
|
_, _ = fmt.Fprintf(inv.Stdout, "Workspace %q removed from favorites.\n", ws.Name)
|
|
return nil
|
|
},
|
|
}
|
|
return cmd
|
|
}
|