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

Method autoupdate

cli/autoupdate.go:14–52  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12)
13
14func (r *RootCmd) autoupdate() *serpent.Command {
15 cmd := &serpent.Command{
16 Annotations: workspaceCommand,
17 Use: "autoupdate <workspace> <always|never>",
18 Short: "Toggle auto-update policy for a workspace",
19 Middleware: serpent.Chain(
20 serpent.RequireNArgs(2),
21 ),
22 Handler: func(inv *serpent.Invocation) error {
23 client, err := r.InitClient(inv)
24 if err != nil {
25 return err
26 }
27
28 policy := strings.ToLower(inv.Args[1])
29 err = validateAutoUpdatePolicy(policy)
30 if err != nil {
31 return xerrors.Errorf("validate policy: %w", err)
32 }
33
34 workspace, err := client.ResolveWorkspace(inv.Context(), inv.Args[0])
35 if err != nil {
36 return xerrors.Errorf("get workspace: %w", err)
37 }
38
39 err = client.UpdateWorkspaceAutomaticUpdates(inv.Context(), workspace.ID, codersdk.UpdateWorkspaceAutomaticUpdatesRequest{
40 AutomaticUpdates: codersdk.AutomaticUpdates(policy),
41 })
42 if err != nil {
43 return xerrors.Errorf("update workspace automatic updates policy: %w", err)
44 }
45 _, _ = fmt.Fprintf(inv.Stdout, "Updated workspace %q auto-update policy to %q\n", workspace.Name, policy)
46 return nil
47 },
48 }
49
50 cmd.Options = append(cmd.Options, cliui.SkipPromptOption())
51 return cmd
52}
53
54func validateAutoUpdatePolicy(arg string) error {
55 switch codersdk.AutomaticUpdates(arg) {

Callers 1

CoreSubcommandsMethod · 0.95

Calls 8

InitClientMethod · 0.95
AutomaticUpdatesTypeAlias · 0.92
SkipPromptOptionFunction · 0.92
validateAutoUpdatePolicyFunction · 0.85
ResolveWorkspaceMethod · 0.80
ContextMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected