/**
 * Created by axetroy on 17-2-14.
 */

const path = require('path');
const process = require('process');
const _ = require('lodash');
const Promise = require('bluebird');
const fs = Promise.promisifyAll(require('fs-extra'));
const prettyjson = require('prettyjson');
const log4js = require('log4js');
const logger = log4js.getLogger('LS');

const config = require('../config');

function *ls(options) {
  const lockJSON = yield fs.readJsonAsync(config.paths.lock);
  lockJSON.repos = lockJSON.repos || [];

  if (_.isEmpty(lockJSON.repos)) {
    logger.warn(`You did not add any repository yet, try run command line: ${config.name} add <repo> [options]`);
  } else {
    const result = {};
    lockJSON.repos.forEach(function (repo) {
      result[repo.source] = result[repo.source] || {};
      result[repo.source][repo.owner] = result[repo.source][repo.owner] || {};
      result[repo.source][repo.owner][repo.name] = repo.path.yellow;
    });
    process.stdout.write(prettyjson.render({
        [path.join(process.env.HOME, config.defaults.base)]: result
      }) + '\n');
  }
}

module.exports = function (options) {
  return ls(options);
};
@@ -756,16 +756,20 @@
 o.source
+.red
 %5D = resu
@@ -782,16 +782,20 @@
 o.source
+.red
 %5D %7C%7C %7B%7D;
@@ -811,32 +811,36 @@
 sult%5Brepo.source
+.red
 %5D%5Brepo.owner%5D = 
@@ -835,16 +835,23 @@
 po.owner
+.yellow
 %5D = resu
@@ -856,32 +856,36 @@
 sult%5Brepo.source
+.red
 %5D%5Brepo.owner%5D %7C%7C
@@ -880,16 +880,23 @@
 po.owner
+.yellow
 %5D %7C%7C %7B%7D;
@@ -920,16 +920,20 @@
 o.source
+.red
 %5D%5Brepo.o
@@ -936,16 +936,23 @@
 po.owner
+.yellow
 %5D%5Brepo.n
@@ -972,15 +972,122 @@
 ath.
-yellow;
+white;%0A    %7D);%0A    let str = prettyjson.render(%7B%0A      %5Bpath.join(process.env.HOME, config.defaults.base)%5D: result
 %0A   

complete then list command print out info