#!/usr/bin/env node

const archy = require('archy')
const chalk = require('chalk')

const coverdeeps = require('.')

/**
 * Colors the percentage
 * If its bigger or equal 100% you get a green and bold color
 * If its bigger or equal 90% you get only a green color
 * If its bigger or equal to 80% you get a yellow color
 * Everything else is red
 * @example
 *   var colordString = coloredPercentage(0.8)
 * @requires chalk
 * @param    {Number} value The percentage represented as unit
 * @return   {String}       Returns a colored String
 */
function coloredPercentage(value)
{
  var result = (value*100).toFixed(2)+'%'

  if(value >= 1)   return chalk.green.bold(result)
  if(value >= 0.9) return chalk.green(result)
  if(value >= 0.8) return chalk.yellow(result)
  if(value >  0)   return chalk.red(result)

  return chalk.red.bold(result)
}

function mapCreateTree(key)
{
  return coverdeeps2archy(this[key], key)
}

function coverdeeps2archy(dependency, key)
{
  const name = dependency.name
  if(!name) return key

  const label = name+': '
  const covered = coloredPercentage(dependency.covered)

  const dependencies = dependency.dependencies
  if(!dependencies) return label+covered

  const result =
  {
    label: label+coloredPercentage(dependency.covered_combined)+' ('+covered+')',
    nodes: Object.keys(dependencies).sort().map(mapCreateTree, dependencies)
  }

  return result
}


const moduleName = process.argv[2] || require('.').name

coverdeeps(moduleName, function(error, result)
{
  if(error) throw error

  console.log(archy(coverdeeps2archy(result)))
})

@@ -845,82 +845,746 @@
 %0A%7D%0A%0A
-function mapCreateTree(key)%0A%7B%0A  return coverdeeps2archy(this%5Bkey%5D, key)%0A%7D%0A
+/**%0A * Creates a tree for every dependency%0A * @example%0A *   Object.keys(dependencies).map(mapCreateTree, dependencies)%0A * @param  %7BString%7D key The name of the dependency%0A * @return %7BObject%7D     Returns a object containing the coverage%0A *                      for the dependency%0A */%0Afunction mapCreateTree(key)%0A%7B%0A  return coverdeeps2archy(this%5Bkey%5D, key)%0A%7D%0A%0A/**%0A * Creates a coverage tree for all dependencies%0A * @param   %7BObject%7D dependency The dependency itself%0A * @param   %7BString%7D %5Bkey%5D      If the dependency has no name it retunrs just the%0A *                              key of the dependency%0A * @returns %7BObject%7D            Returns a archy compatible object containing%0A *                              a label and nodes property%0A */
 %0Afun
@@ -2056,16 +2056,66 @@
 sult%0A%7D%0A%0A
+/**%0A * @constant%0A * @type %7BString%7D%0A * @default%0A */
 %0Aconst m
@@ -2164,16 +2164,123 @@
 ).name%0A%0A
+/**%0A * Invokes coverdeeps and calls it with either the a%0A * process argument or the name of the module%0A */%0A
 coverdee

Add documentation to the other functions