/**
 * 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.red] = result[repo.source.red] || {};
      result[repo.source.red][repo.owner.yellow] = result[repo.source.red][repo.owner.yellow] || {};
      result[repo.source.red][repo.owner.yellow][repo.name] = repo.path.white;
    });
    process.stdout.write(prettyjson.render({
        [path.join(process.env.HOME, config.defaults.base)]: result
      }) + '\n');
  }
}

module.exports = function (options) {
  return ls(options);
};
@@ -954,16 +954,22 @@
 epo.name
+.green
 %5D = repo
@@ -981,16 +981,16 @@
 .white;%0A
-
     %7D);%0A
@@ -1092,16 +1092,22 @@
 ts.base)
+.white
 %5D: resul
@@ -1122,17 +1122,147 @@
 %7D) + '%5Cn
-'
+%5Cn');%0A    console.log(%60Repository Source%60.red);%0A    console.log(%60Repository Owner%60.yellow);%0A    console.log(%60Repository Name%60.green
 );%0A  %7D%0A%7D

update print format