const chalk = require('chalk')
const { deleteProfile } = require('../profile')
const { handleError } = require('../error')

async function builder (yargs) {
  yargs.option('verbose', {
    alias: 'v',
    type: 'boolean',
    describe: 'Console will receive verbose error output'
  })
}

async function handler (argv) {
  try {
    const profilePath = await deleteProfile()

    console.log(
      chalk.green(`Logout successful, deleted profile at ${profilePath}`)
    )
  } catch (err) {
    handleError(err, 'Logout failed', argv.verbose)
  }
}

module.exports = {
  builder,
  handler,
  command: 'logout',
  describe: 'Logout and remove local profile'
}
