All files / kanbn/src/controller archive.js

96.87% Statements 62/64
100% Branches 13/13
100% Functions 3/3
96.87% Lines 62/64

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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 651x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 5x 5x 5x 1x 1x 1x 4x 4x 5x 1x 1x 1x 3x 3x 3x 5x 1x 1x 1x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x  
const kanbn = require('../main');
const utility = require('../utility');
 
/**
 * Archive a task
 * @param {string} taskId
 */
function archiveTask(taskId) {
  kanbn
  .archiveTask(taskId)
  .then(taskId => {
    console.log(`Archived task "${taskId}"`);
  })
  .catch(error => {
    utility.error(error);
  });
}
 
/**
 * Show a list of archived task filenames
 */
function listArchivedTasks() {
  kanbn
  .listArchivedTasks()
  .then(archivedTasks => {
    console.log(archivedTasks.join('\n'));
  })
  .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;
  }
 
  // Check if we're listing archived tasks
  if (args.list) {
    listArchivedTasks();
    return;
  }
 
  // Get the task that we're archiving
  const taskId = args._[1];
  if (!taskId) {
    utility.error('No task id specified\nTry running {b}kanbn archive "task id"{b}');
    return;
  }
 
  // Make sure the task exists
  try {
    await kanbn.taskExists(taskId);
  } catch (error) {
    utility.error(error);
    return;
  }
 
  // Archive task
  archiveTask(taskId);
};