All files / kanbn/src/controller status.js

96% Statements 72/75
96.42% Branches 27/28
100% Functions 1/1
96% Lines 72/75

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 65 66 67 68 69 70 71 72 73 74 75 761x 1x 1x 1x 1x 1x 11x 11x 11x 1x 1x 1x 10x 10x 10x 11x 2x 2x 2x 1x 1x 2x 10x 10x 10x 11x 2x 2x 2x 3x 3x 1x 1x 1x 2x 2x 1x 2x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 3x 3x 3x 3x 3x 9x 6x 6x 9x 9x 9x 9x 9x 5x 5x 4x 9x     4x 9x 9x   9x 1x  
const kanbn = require('../main');
const utility = require('../utility');
const chrono = require('chrono-node');
const yaml = require('yamljs');
 
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 sprint number or name
  let sprint = null;
  if (args.sprint) {
    sprint = utility.strArg(args.sprint);
    const sprintNumber = parseInt(sprint);
    if (!isNaN(sprintNumber)) {
      sprint = sprintNumber;
    }
  }
 
  // Get filter dates
  let dates = null;
  if (args.date) {
    dates = utility.arrayArg(args.date);
    if (dates.length) {
      for (let i = 0; i < dates.length; i++) {
        const dateValue = chrono.parseDate(dates[i]);
        if (dateValue === null) {
          utility.error('Unable to parse date');
          return;
        }
        dates[i] = dateValue;
      }
    }
  }
 
  // Get status
  kanbn
  .status(
    args.quiet,
    args.untracked,
    args.due,
    sprint,
    dates
  )
  .then(output => {
    if (args.quiet && args.untracked && !args.json) {
      console.log(
        output.length
          ? output.join('\n')
          : 'No untracked tasks found'
      );
    } else {
      console.log(args.json ? JSON.stringify(output, null, 2) : yaml.stringify(output, 4, 2));
    }
  })
  .then(async () => {
 
    // Only load tasks for the hint when it would actually be shown
    if (args.json || args.quiet) {
      return;
    }
    const index = await kanbn.getIndex();
    if (!kanbn.isVerbose(index)) {
      return;
    }
    utility.showDateDriftHint(await kanbn.findDateDrift());
  })
  .catch(error => {
    utility.error(error);
  });
};