(orgContext *OrganizationContext, settings []organizationSetting)
| 111 | } |
| 112 | |
| 113 | func (r *RootCmd) setOrganizationSettings(orgContext *OrganizationContext, settings []organizationSetting) *serpent.Command { |
| 114 | cmd := &serpent.Command{ |
| 115 | Use: "set", |
| 116 | Short: "Update specified organization setting.", |
| 117 | Long: FormatExamples( |
| 118 | Example{ |
| 119 | Description: "Update group sync settings.", |
| 120 | Command: "coder organization settings set groupsync < input.json", |
| 121 | }, |
| 122 | ), |
| 123 | Options: []serpent.Option{}, |
| 124 | Middleware: serpent.Chain( |
| 125 | serpent.RequireNArgs(0), |
| 126 | ), |
| 127 | Handler: func(inv *serpent.Invocation) error { |
| 128 | return inv.Command.HelpHandler(inv) |
| 129 | }, |
| 130 | } |
| 131 | |
| 132 | for _, set := range settings { |
| 133 | patch := set.Patch |
| 134 | cmd.Children = append(cmd.Children, &serpent.Command{ |
| 135 | Use: set.Name, |
| 136 | Aliases: set.Aliases, |
| 137 | Short: set.Short, |
| 138 | Options: []serpent.Option{}, |
| 139 | Middleware: serpent.Chain( |
| 140 | serpent.RequireNArgs(0), |
| 141 | ), |
| 142 | Handler: func(inv *serpent.Invocation) error { |
| 143 | client, err := r.InitClient(inv) |
| 144 | if err != nil { |
| 145 | return err |
| 146 | } |
| 147 | |
| 148 | ctx := inv.Context() |
| 149 | var org codersdk.Organization |
| 150 | |
| 151 | if !set.DisableOrgContext { |
| 152 | org, err = orgContext.Selected(inv, client) |
| 153 | if err != nil { |
| 154 | return err |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | // Read in the json |
| 159 | inputData, err := io.ReadAll(inv.Stdin) |
| 160 | if err != nil { |
| 161 | return xerrors.Errorf("reading stdin: %w", err) |
| 162 | } |
| 163 | |
| 164 | output, err := patch(ctx, client, org.ID, inputData) |
| 165 | if err != nil { |
| 166 | return xerrors.Errorf("patching %q: %w", set.Name, err) |
| 167 | } |
| 168 | |
| 169 | settingJSON, err := json.Marshal(output) |
| 170 | if err != nil { |
no test coverage detected