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

Method showOrganizationRoles

cli/organizationroles.go:36–107  ·  view source on GitHub ↗
(orgContext *OrganizationContext)

Source from the content-addressed store, hash-verified

34}
35
36func (r *RootCmd) showOrganizationRoles(orgContext *OrganizationContext) *serpent.Command {
37 formatter := cliui.NewOutputFormatter(
38 cliui.ChangeFormatterData(
39 cliui.TableFormat([]roleTableRow{}, []string{"name", "display name", "site permissions", "organization permissions", "user permissions"}),
40 func(data any) (any, error) {
41 inputs, ok := data.([]codersdk.AssignableRoles)
42 if !ok {
43 return nil, xerrors.Errorf("expected []codersdk.AssignableRoles got %T", data)
44 }
45
46 tableRows := make([]roleTableRow, 0)
47 for _, input := range inputs {
48 tableRows = append(tableRows, roleToTableView(input.Role))
49 }
50
51 return tableRows, nil
52 },
53 ),
54 cliui.JSONFormat(),
55 )
56
57 cmd := &serpent.Command{
58 Use: "show [role_names ...]",
59 Short: "Show role(s)",
60 Handler: func(inv *serpent.Invocation) error {
61 client, err := r.InitClient(inv)
62 if err != nil {
63 return err
64 }
65
66 ctx := inv.Context()
67 org, err := orgContext.Selected(inv, client)
68 if err != nil {
69 return err
70 }
71
72 roles, err := client.ListOrganizationRoles(ctx, org.ID)
73 if err != nil {
74 return xerrors.Errorf("listing roles: %w", err)
75 }
76
77 if len(inv.Args) > 0 {
78 // filter roles
79 filtered := make([]codersdk.AssignableRoles, 0)
80 for _, role := range roles {
81 if slices.ContainsFunc(inv.Args, func(s string) bool {
82 return strings.EqualFold(s, role.Name)
83 }) {
84 filtered = append(filtered, role)
85 }
86 }
87 roles = filtered
88 }
89
90 out, err := formatter.Format(inv.Context(), roles)
91 if err != nil {
92 return err
93 }

Callers 1

organizationRolesMethod · 0.95

Calls 13

InitClientMethod · 0.95
FormatMethod · 0.95
AttachOptionsMethod · 0.95
NewOutputFormatterFunction · 0.92
ChangeFormatterDataFunction · 0.92
TableFormatFunction · 0.92
JSONFormatFunction · 0.92
InfofFunction · 0.92
roleToTableViewFunction · 0.85
SelectedMethod · 0.80
ListOrganizationRolesMethod · 0.80
ContextMethod · 0.65

Tested by

no test coverage detected