| 289 | } |
| 290 | |
| 291 | func deleteRoleCmd(cli *cli) *cobra.Command { |
| 292 | cmd := &cobra.Command{ |
| 293 | Use: "delete", |
| 294 | Aliases: []string{"rm"}, |
| 295 | Short: "Delete a role", |
| 296 | Long: "Delete a role.\n\n" + |
| 297 | "To delete interactively, use `auth0 roles delete`.\n\n" + |
| 298 | "To delete non-interactively, supply the role id and the `--force` flag to skip confirmation.", |
| 299 | Example: ` auth0 roles delete |
| 300 | auth0 roles rm |
| 301 | auth0 roles delete <role-id> |
| 302 | auth0 roles delete <role-id> --force |
| 303 | auth0 roles delete <role-id> <role-id2> <role-idn> |
| 304 | auth0 roles delete <role-id> <role-id2> <role-idn> --force`, |
| 305 | RunE: func(cmd *cobra.Command, args []string) error { |
| 306 | var ids []string |
| 307 | if len(args) == 0 { |
| 308 | if err := roleID.PickMany(cmd, &ids, cli.rolePickerOptions); err != nil { |
| 309 | return err |
| 310 | } |
| 311 | } else { |
| 312 | ids = args |
| 313 | } |
| 314 | |
| 315 | if !cli.force && canPrompt(cmd) { |
| 316 | if confirmed := prompt.Confirm("Are you sure you want to proceed?"); !confirmed { |
| 317 | return nil |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | return ansi.ProgressBar("Deleting Role(s)", ids, func(_ int, id string) error { |
| 322 | if id != "" { |
| 323 | if _, err := cli.api.Role.Read(cmd.Context(), id); err != nil { |
| 324 | return fmt.Errorf("failed to delete role with ID %q: %w", id, err) |
| 325 | } |
| 326 | |
| 327 | if err := cli.api.Role.Delete(cmd.Context(), id); err != nil { |
| 328 | return fmt.Errorf("failed to delete role with ID %q: %w", id, err) |
| 329 | } |
| 330 | } |
| 331 | return nil |
| 332 | }) |
| 333 | }, |
| 334 | } |
| 335 | |
| 336 | cmd.Flags().BoolVar(&cli.force, "force", false, "Skip confirmation.") |
| 337 | |
| 338 | return cmd |
| 339 | } |
| 340 | |
| 341 | func (c *cli) rolePickerOptions(ctx context.Context) (pickerOptions, error) { |
| 342 | list, err := c.api.Role.List(ctx) |