const asciiArt = require('ascii-art')
const { deleteProfile } = require('../profile')

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(
      asciiArt.style(`Logout successful, deleted profile at ${profilePath}`, 'green', true)
    )
  } catch (error) {
    const errorMessage = error.message || error
    console.error(`Logout failed: ${errorMessage}`)

    if (argv.detailedErrors) {
      console.log(error)
    }
  }
}

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