mirror of
https://github.com/coder/coder.git
synced 2026-10-16 14:48:56 +08:00
`coder autoupdate` has registered `-y/--yes` since #10438 but never prompts, so the flag did nothing. This PR removes it. **Breaking change:** `coder autoupdate` no longer accepts `-y/--yes`. Scripts that pass it now fail with `unknown shorthand flag: 'y'`. To fix them, drop the flag; it never had an effect. <details> <summary>Decisions</summary> - The first version kept `-y` as a hidden no-op so existing scripts wouldn't break. - Reviewers preferred removing it outright as a breaking change, since a deprecation period would end in the same removal and the hidden flag is cruft. - The title uses `fix!:` and the PR carries `release/breaking`, so the release tooling lists it under breaking changes. - `cliui.HiddenSkipPromptOption()` landed on `main` through the organizations create PR and stays there for that command; this PR no longer touches it. - The test now pins the new behavior: passing `-y` returns an unknown flag error. </details> Closes [CLI-33](https://linear.app/codercom/issue/CLI-33) _This PR was generated by Coder Agents on behalf of @nickvigilante._
60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
"github.com/coder/coder/v2/codersdk"
|
|
"github.com/coder/serpent"
|
|
)
|
|
|
|
func (r *RootCmd) autoupdate() *serpent.Command {
|
|
cmd := &serpent.Command{
|
|
Annotations: workspaceCommand,
|
|
Use: "autoupdate <workspace> <always|never>",
|
|
Short: "Toggle auto-update policy for a workspace",
|
|
Middleware: serpent.Chain(
|
|
serpent.RequireNArgs(2),
|
|
),
|
|
Handler: func(inv *serpent.Invocation) error {
|
|
client, err := r.InitClient(inv)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
policy := strings.ToLower(inv.Args[1])
|
|
err = validateAutoUpdatePolicy(policy)
|
|
if err != nil {
|
|
return xerrors.Errorf("validate policy: %w", err)
|
|
}
|
|
|
|
workspace, err := client.ResolveWorkspace(inv.Context(), inv.Args[0])
|
|
if err != nil {
|
|
return xerrors.Errorf("get workspace: %w", err)
|
|
}
|
|
|
|
err = client.UpdateWorkspaceAutomaticUpdates(inv.Context(), workspace.ID, codersdk.UpdateWorkspaceAutomaticUpdatesRequest{
|
|
AutomaticUpdates: codersdk.AutomaticUpdates(policy),
|
|
})
|
|
if err != nil {
|
|
return xerrors.Errorf("update workspace automatic updates policy: %w", err)
|
|
}
|
|
_, _ = fmt.Fprintf(inv.Stdout, "Updated workspace %q auto-update policy to %q\n", workspace.Name, policy)
|
|
return nil
|
|
},
|
|
}
|
|
|
|
return cmd
|
|
}
|
|
|
|
func validateAutoUpdatePolicy(arg string) error {
|
|
switch codersdk.AutomaticUpdates(arg) {
|
|
case codersdk.AutomaticUpdatesAlways, codersdk.AutomaticUpdatesNever:
|
|
return nil
|
|
default:
|
|
return xerrors.Errorf("invalid option %q must be either of %q or %q", arg, codersdk.AutomaticUpdatesAlways, codersdk.AutomaticUpdatesNever)
|
|
}
|
|
}
|