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

Method printOrganizationSetting

cli/organizationsettings.go:189–256  ·  view source on GitHub ↗
(orgContext *OrganizationContext, settings []organizationSetting)

Source from the content-addressed store, hash-verified

187}
188
189func (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)

Callers 1

organizationSettingsMethod · 0.95

Calls 8

InitClientMethod · 0.95
FormatExamplesFunction · 0.85
SelectedMethod · 0.80
ContextMethod · 0.65
fetchFunction · 0.50
ErrorfMethod · 0.45
MarshalMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected