| 621 | } |
| 622 | |
| 623 | func deleteUserCmd(cli *cli) *cobra.Command { |
| 624 | cmd := &cobra.Command{ |
| 625 | Use: "delete", |
| 626 | Aliases: []string{"rm"}, |
| 627 | Short: "Delete a user", |
| 628 | Long: "Delete a user.\n\n" + |
| 629 | "To delete interactively, use `auth0 users delete` with no arguments.\n\n" + |
| 630 | "To delete non-interactively, supply the user id and the `--force` flag to skip confirmation.", |
| 631 | Example: ` auth0 users delete |
| 632 | auth0 users rm |
| 633 | auth0 users delete <user-id> |
| 634 | auth0 users delete <user-id> --force |
| 635 | auth0 users delete <user-id> <user-id2> <user-idn> |
| 636 | auth0 users delete <user-id> <user-id2> <user-idn> --force`, |
| 637 | RunE: func(cmd *cobra.Command, args []string) error { |
| 638 | var ids []string |
| 639 | if len(args) == 0 { |
| 640 | var id string |
| 641 | if err := userID.Ask(cmd, &id); err != nil { |
| 642 | return err |
| 643 | } |
| 644 | ids = append(ids, id) |
| 645 | } else { |
| 646 | ids = args |
| 647 | } |
| 648 | |
| 649 | if !cli.force && canPrompt(cmd) { |
| 650 | if confirmed := prompt.Confirm("Are you sure you want to proceed?"); !confirmed { |
| 651 | return nil |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | return ansi.ProgressBar("Deleting user(s)", ids, func(_ int, id string) error { |
| 656 | if id != "" { |
| 657 | if _, err := cli.api.User.Read(cmd.Context(), id); err != nil { |
| 658 | return fmt.Errorf("failed to delete user with ID %q: %w", id, err) |
| 659 | } |
| 660 | |
| 661 | if err := cli.api.User.Delete(cmd.Context(), id); err != nil { |
| 662 | return fmt.Errorf("failed to delete user with ID %q: %w", id, err) |
| 663 | } |
| 664 | } |
| 665 | return nil |
| 666 | }) |
| 667 | }, |
| 668 | } |
| 669 | |
| 670 | cmd.Flags().BoolVar(&cli.force, "force", false, "Skip confirmation.") |
| 671 | |
| 672 | return cmd |
| 673 | } |
| 674 | |
| 675 | func updateUserCmd(cli *cli) *cobra.Command { |
| 676 | var ( |