All files / kanbn/src/controller task.js

98.11% Statements 52/53
100% Branches 13/13
100% Functions 2/2
98.11% Lines 52/53

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 541x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 2x 3x 1x 1x 1x 1x 1x 3x 3x   3x 3x 1x 1x 6x 6x 1x 1x 1x 5x 5x 5x 6x 1x 1x 1x 4x 4x 4x 4x 6x 1x 1x 1x 3x 3x 3x 1x  
const kanbn = require("../main");
const utility = require("../utility");
const parseTask = require("../parse-task");
const marked = require("marked");
const markedTerminalRenderer = require("marked-terminal");
 
/**
 * Show task information
 * @param {string} taskId
 */
function showTask(taskId, json = false) {
  kanbn
    .getTask(taskId)
    .then((task) => {
      if (json) {
        console.log(JSON.stringify(task, null, 2));
      } else {
        marked.setOptions({
          renderer: new markedTerminalRenderer(),
        });
        console.log(marked(parseTask.json2md(task)));
      }
    })
    .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;
  }
 
  // Get the task that we're showing
  const taskId = args._[1];
  if (!taskId) {
    utility.error('No task id specified\nTry running {b}kanbn task "task id"{b}');
    return;
  }
 
  // Make sure the task exists
  try {
    await kanbn.taskExists(taskId);
  } catch (error) {
    utility.error(error);
    return;
  }
 
  // Show the task
  showTask(taskId, args.json);
};