()
| 26 | ) |
| 27 | |
| 28 | func newAuthDeleteAccountCmd() *cobra.Command { |
| 29 | cmd := &cobra.Command{ |
| 30 | Use: "delete-account", |
| 31 | Short: "delete your account", |
| 32 | RunE: func(cmd *cobra.Command, args []string) error { |
| 33 | // Get user information to make sure the user knows the account she is deleting |
| 34 | contextResp, err := action.NewConfigCurrentContext(ActionOpts).Run() |
| 35 | if err != nil { |
| 36 | return err |
| 37 | } |
| 38 | |
| 39 | fmt.Printf("You are about to delete your account %q\n", contextResp.CurrentUser.Email) |
| 40 | |
| 41 | // Ask for confirmation |
| 42 | if err := confirmDeletion(); err != nil { |
| 43 | return err |
| 44 | } |
| 45 | |
| 46 | // Account deletion |
| 47 | if err := action.NewDeleteAccount(ActionOpts).Run(); err != nil { |
| 48 | return err |
| 49 | } |
| 50 | |
| 51 | // Remove token from config file |
| 52 | viper.Set(confOptions.authToken.viperKey, "") |
| 53 | if err := viper.WriteConfig(); err != nil { |
| 54 | return err |
| 55 | } |
| 56 | |
| 57 | logger.Info().Msg("Account deleted :(") |
| 58 | return nil |
| 59 | }, |
| 60 | } |
| 61 | |
| 62 | return cmd |
| 63 | } |
| 64 | |
| 65 | // confirmDeletion asks the user to type a random string |
| 66 | func confirmDeletion() error { |
no test coverage detected