(orgContext *OrganizationContext, settings []organizationSetting)
| 187 | } |
| 188 | |
| 189 | func (r *RootCmd) printOrganizationSetting(orgContext *OrganizationContext, settings []organizationSetting) *serpent.Command { |
| 190 | cmd := &serpent.Command{ |
| 191 | Use: "show", |
| 192 | Short: "Outputs specified organization setting.", |
| 193 | Long: FormatExamples( |
| 194 | Example{ |
| 195 | Description: "Output group sync settings.", |
| 196 | Command: "coder organization settings show groupsync", |
| 197 | }, |
| 198 | ), |
| 199 | Options: []serpent.Option{}, |
| 200 | Middleware: serpent.Chain( |
| 201 | serpent.RequireNArgs(0), |
| 202 | ), |
| 203 | Handler: func(inv *serpent.Invocation) error { |
| 204 | return inv.Command.HelpHandler(inv) |
| 205 | }, |
| 206 | } |
| 207 | |
| 208 | for _, set := range settings { |
| 209 | fetch := set.Fetch |
| 210 | cmd.Children = append(cmd.Children, &serpent.Command{ |
| 211 | Use: set.Name, |
| 212 | Aliases: set.Aliases, |
| 213 | Short: set.Short, |
| 214 | Options: []serpent.Option{}, |
| 215 | Middleware: serpent.Chain( |
| 216 | serpent.RequireNArgs(0), |
| 217 | ), |
| 218 | Handler: func(inv *serpent.Invocation) error { |
| 219 | client, err := r.InitClient(inv) |
| 220 | if err != nil { |
| 221 | return err |
| 222 | } |
| 223 | |
| 224 | ctx := inv.Context() |
| 225 | var org codersdk.Organization |
| 226 | if !set.DisableOrgContext { |
| 227 | org, err = orgContext.Selected(inv, client) |
| 228 | if err != nil { |
| 229 | return err |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | output, err := fetch(ctx, client, org.ID) |
| 234 | if err != nil { |
| 235 | return xerrors.Errorf("patching %q: %w", set.Name, err) |
| 236 | } |
| 237 | |
| 238 | settingJSON, err := json.Marshal(output) |
| 239 | if err != nil { |
| 240 | return xerrors.Errorf("failed to marshal organization setting %s: %w", inv.Args[0], err) |
| 241 | } |
| 242 | |
| 243 | var dst bytes.Buffer |
| 244 | err = json.Indent(&dst, settingJSON, "", "\t") |
| 245 | if err != nil { |
| 246 | return xerrors.Errorf("failed to indent organization setting as json %s: %w", inv.Args[0], err) |
no test coverage detected