All files / kanbn/src/controller remove-all.js

95.74% Statements 45/47
100% Branches 10/10
100% Functions 2/2
95.74% Lines 45/47

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 481x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x   2x 2x 1x 1x 4x 4x 4x 1x 1x 1x 3x 3x 4x 1x 1x 1x 4x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 2x   2x 2x 1x  
const kanbn = require('../main');
const utility = require('../utility');
const inquirer = require('inquirer');
 
/**
 * Nuke kanbn
 */
function removeAll() {
  kanbn.removeAll()
  .then(() => {
    console.log('kanbn has been removed');
  })
  .catch(error => {
    utility.error(error);
  });
}
 
module.exports = async args => {
 
  // Make sure kanbn has been initialised
  if (!await kanbn.initialised()) {
    utility.error('Kanbn has not been initialised in this folder\nTry running: {b}kanbn init{b}');
    return;
  }
 
  // If the force flag is specified, remove kanbn without asking
  if (args.force) {
    removeAll();
 
  // Otherwise, prompt for confirmation first
  } else {
    inquirer.prompt([
      {
        type: 'confirm',
        message: 'Are you sure you want to remove kanbn and all tasks?',
        name: 'sure',
        default: false
      }
    ]).then(async answers => {
      if (answers.sure) {
        removeAll();
      }
    }).catch(error => {
      utility.error(error);
    })
  }
};