MCPcopy Create free account
hub / github.com/auth0/auth0-cli / createRoleCmd

Function createRoleCmd

internal/cli/roles.go:167–216  ·  view source on GitHub ↗
(cli *cli)

Source from the content-addressed store, hash-verified

165}
166
167func createRoleCmd(cli *cli) *cobra.Command {
168 var inputs struct {
169 Name string
170 Description string
171 }
172
173 cmd := &cobra.Command{
174 Use: "create",
175 Args: cobra.NoArgs,
176 Short: "Create a new role",
177 Long: "Create a new role.\n\n" +
178 "To create interactively, use `auth0 roles create` with no arguments.\n\n" +
179 "To create non-interactively, supply the role name and description through the flags.",
180 Example: ` auth0 roles create
181 auth0 roles create --name myrole --description "awesome role"
182 auth0 roles create -n myrole -d "awesome role" --json-compact
183 auth0 roles create -n myrole -d "awesome role" --json`,
184 RunE: func(cmd *cobra.Command, args []string) error {
185 if err := roleName.Ask(cmd, &inputs.Name, nil); err != nil {
186 return err
187 }
188
189 if err := roleDescription.Ask(cmd, &inputs.Description, nil); err != nil {
190 return err
191 }
192
193 r := &management.Role{
194 Name: &inputs.Name,
195 Description: &inputs.Description,
196 }
197
198 if err := ansi.Waiting(func() error {
199 return cli.api.Role.Create(cmd.Context(), r)
200 }); err != nil {
201 return fmt.Errorf("failed to create role: %w", err)
202 }
203
204 cli.renderer.RoleCreate(r)
205
206 return nil
207 },
208 }
209
210 cmd.Flags().BoolVar(&cli.json, "json", false, "Output in json format.")
211 cmd.Flags().BoolVar(&cli.jsonCompact, "json-compact", false, "Output in compact json format.")
212 roleName.RegisterString(cmd, &inputs.Name, "")
213 roleDescription.RegisterString(cmd, &inputs.Description, "")
214
215 return cmd
216}
217
218func updateRoleCmd(cli *cli) *cobra.Command {
219 var inputs struct {

Callers 1

rolesCmdFunction · 0.85

Calls 6

WaitingFunction · 0.92
ErrorfMethod · 0.80
RoleCreateMethod · 0.80
RegisterStringMethod · 0.80
CreateMethod · 0.65
AskMethod · 0.45

Tested by

no test coverage detected