(orgContext *OrganizationContext)
| 107 | } |
| 108 | |
| 109 | func (r *RootCmd) createOrganizationRole(orgContext *OrganizationContext) *serpent.Command { |
| 110 | formatter := cliui.NewOutputFormatter( |
| 111 | cliui.ChangeFormatterData( |
| 112 | cliui.TableFormat([]roleTableRow{}, []string{"name", "display name", "site permissions", "organization permissions", "user permissions"}), |
| 113 | func(data any) (any, error) { |
| 114 | typed, _ := data.(codersdk.Role) |
| 115 | return []roleTableRow{roleToTableView(typed)}, nil |
| 116 | }, |
| 117 | ), |
| 118 | cliui.JSONFormat(), |
| 119 | ) |
| 120 | |
| 121 | var ( |
| 122 | dryRun bool |
| 123 | jsonInput bool |
| 124 | ) |
| 125 | |
| 126 | cmd := &serpent.Command{ |
| 127 | Use: "create <role_name>", |
| 128 | Short: "Create a new organization custom role", |
| 129 | Long: FormatExamples( |
| 130 | Example{ |
| 131 | Description: "Run with an input.json file", |
| 132 | Command: "coder organization -O <organization_name> roles create --stdin < role.json", |
| 133 | }, |
| 134 | ), |
| 135 | Options: []serpent.Option{ |
| 136 | cliui.SkipPromptOption(), |
| 137 | { |
| 138 | Name: "dry-run", |
| 139 | Description: "Does all the work, but does not submit the final updated role.", |
| 140 | Flag: "dry-run", |
| 141 | Value: serpent.BoolOf(&dryRun), |
| 142 | }, |
| 143 | { |
| 144 | Name: "stdin", |
| 145 | Description: "Reads stdin for the json role definition to upload.", |
| 146 | Flag: "stdin", |
| 147 | Value: serpent.BoolOf(&jsonInput), |
| 148 | }, |
| 149 | }, |
| 150 | Middleware: serpent.Chain( |
| 151 | serpent.RequireRangeArgs(0, 1), |
| 152 | ), |
| 153 | Handler: func(inv *serpent.Invocation) error { |
| 154 | ctx := inv.Context() |
| 155 | client, err := r.InitClient(inv) |
| 156 | if err != nil { |
| 157 | return err |
| 158 | } |
| 159 | org, err := orgContext.Selected(inv, client) |
| 160 | if err != nil { |
| 161 | return err |
| 162 | } |
| 163 | |
| 164 | existingRoles, err := client.ListOrganizationRoles(ctx, org.ID) |
| 165 | if err != nil { |
| 166 | return xerrors.Errorf("listing existing roles: %w", err) |
no test coverage detected