const fs = require('fs-extra');
const inquirer = require('inquirer');
exports.command = 'clean';
exports.description = 'Remove .idyll folder';

const PATH = './.idyll';

exports.handler = async _ => {
  try {
    let isTokenExists = await checkIfTokenExists();
    if (isTokenExists) {
      let userAnswer = await confirm();
      if (userAnswer === 'Yes') {
        removeIdyll();
      }
    } else {
      removeIdyll();
    }
  } catch (e) {
    console.log(e);
  }
};

checkIfTokenExists = _ => {
  return fs.pathExists(`${PATH}/token`);
};

confirm = async _ => {
  const userResponse = await inquirer.prompt([
    {
      type: 'list',
      name: 'confirm',
      message: `This command will remove the idyll cache folder, including your idyll.pub token.
      Subsequent deploys to idyll.pub will receive a new URL. 
      Are you sure you wish to continue?`,
      choices: ['Yes', 'No']
    }
  ]);
  return userResponse.confirm;
};

removeIdyll = _ => {
  fs.remove(PATH, err => {
    if (err) return console.error(err);
  });
};

@@ -315,16 +315,21 @@
  confirm
+Clean
 ();%0A    
@@ -348,18 +348,8 @@
 swer
- === 'Yes'
 ) %7B%0A
@@ -543,16 +543,21 @@
 %0Aconfirm
+Clean
  = async
@@ -634,12 +634,15 @@
 e: '
-list
+confirm
 ',%0A 
@@ -652,32 +652,37 @@
   name: 'confirm
+Clean
 ',%0A      message
@@ -881,30 +881,21 @@
     
-choices: %5B'Yes', 'No'%5D
+default: true
 %0A   
@@ -932,16 +932,21 @@
 .confirm
+Clean
 ;%0A%7D;%0A%0Are

add type confirm