forget.ts 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. import fs from 'fs'
  2. import chalk from 'chalk'
  3. import ExitCodes from '../../ExitCodes'
  4. import AccountsCommandBase from '../../base/AccountsCommandBase'
  5. import { NamedKeyringPair } from '../../Types'
  6. export default class AccountForget extends AccountsCommandBase {
  7. static description = 'Forget (remove) account from the list of available accounts'
  8. async run() {
  9. const accounts: NamedKeyringPair[] = this.fetchAccounts()
  10. if (!accounts.length) {
  11. this.error('No accounts found!', { exit: ExitCodes.NoAccountFound })
  12. }
  13. const choosenAccount: NamedKeyringPair = await this.promptForAccount(accounts, null, 'Select an account to forget')
  14. await this.requireConfirmation('Are you sure you want this account to be forgotten?')
  15. const accountFilePath: string = this.getAccountFilePath(choosenAccount)
  16. try {
  17. fs.unlinkSync(accountFilePath)
  18. } catch (e) {
  19. this.error(`Could not remove account file (${accountFilePath}). Permissions issue?`, {
  20. exit: ExitCodes.FsOperationFailed,
  21. })
  22. }
  23. this.log(chalk.greenBright(`\nAccount has been forgotten!`))
  24. }
  25. }