<commit_before>var path = require('path');

module.exports = {debugFunction: debug}
process.stdin.setEncoding('utf8');
var prompts = require('./prompts');
var debugSupport = true;

function parseArgs(args) {
  var options = {}

  for (var i = 0; i < args.length; i++) {
    switch (args[i]) {
      case "--generatorPath":
      {
        options.generatorPath = (++i < args.length) ? args[i] : null;
        break;
      }
      case "--generatorName":
      {
        options.generatorName = (++i < args.length) ? args[i] : null;
        break;
      }
      case "--yeoman":
      {
        options.yeoman = (++i < args.length) ? args[i] : null;
        break;
      }
      case "--arguments":
      {
        options.arguments = (++i < args.length) ? args[i].split(' ') : null;
        break;
      }
      case "--plain":
      {
        options.plain = true;
        break;
      }
      default: //do nothing
    }
  }

  return options;
}

var options = parseArgs(process.argv.slice(2));

var prefix = (options.yeoman ? options.yeoman + path.sep + 'node_modules' + path.sep : '');
var inquirer = require(prefix + 'inquirer');
var yeomanEnv = require(prefix + 'yeoman-environment');


var env = yeomanEnv.createEnv(options.arguments, null, new Adapter);
var inputHandler = (function () {
  var start = false;
  var handlerCallback = null;
  var chunkTotal = '';
  var listener = function (chunk) {
    if (chunk != null) {
      debug('current chunk ' + chunk);
      chunkTotal += chunk;
      if (chunk.indexOf('\n') != -1) {
        debug('handle total chunks ' + chunkTotal);
        handlerCallback(chunkTotal);
        chunkTotal = '';
      }
    }
  };

  process.stdin.on('data', listener);


  return {
    waitInput: function (getResultFunction, question, callback) {


      if (!start) {
        //process.stdin.removeAllListeners('readable');

        start = true;
      }

      handlerCallback = function (chunk) {
        handlerCallback = null;
        process.stdin.pause();
        callback(getResultFunction(question, chunk));
      }
    }
  }
})();

//will works without hacks in the next versions
var callbackDone = function () {
  debug('done run generator');
}
if (options.generatorName) {
  env.lookup(function () {
    env.run(generatorName, null, callbackDone);
  });
} else if (options.generatorPath) {
  env.register(options.generatorPath, 'angular');
  env.run('angular', callbackDone);
} else {
  throw new Error("You should specify generatorName or generatorPath");
}
/**
 * @constructor
 */
function Adapter() {
  debug('adapter create');
  this.prompt = inquirer.createPromptModule();

  Object.keys(this.prompt.prompts).forEach(function (name) {
    this.prompt.registerPrompt(name, Prompt.bind(null, prompts.handlers[name] || prompts.defaultHandler));
  }, this);


  this.log = yeomanEnv.util.log();

}


/**
 * @constructor
 */
function Prompt(getResultFunction, question, rl, answers) {
  this.question = question;
  this.rl = rl;
  this.answers = answers;


  this.run = function (callback) {
    printMessage(question);<commit_msg>working solution: change dir to package and run lookup<commit_after>var path = require('path');

module.exports = {debugFunction: debug}
process.stdin.setEncoding('utf8');
var prompts = require('./prompts');
var debugSupport = true;

function parseArgs(args) {
  var options = {}

  for (var i = 0; i < args.length; i++) {
    switch (args[i]) {
      case "--generatorPath":
      {
        options.generatorPath = (++i < args.length) ? args[i] : null;
        break;
      }
      case "--generatorName":
      {
        options.generatorName = (++i < args.length) ? args[i] : null;
        break;
      }
      case "--yeoman":
      {
        options.yeoman = (++i < args.length) ? args[i] : null;
        break;
      }
      case "--arguments":
      {
        options.arguments = (++i < args.length) ? args[i].split(' ') : null;
        break;
      }
      case "--plain":
      {
        options.plain = true;
        break;
      }
      default: //do nothing
    }
  }

  return options;
}

var options = parseArgs(process.argv.slice(2));

var prefix = (options.yeoman ? options.yeoman + path.sep + 'node_modules' + path.sep : '');
var inquirer = require(prefix + 'inquirer');
var yeomanEnv = require(prefix + 'yeoman-environment');


var env = yeomanEnv.createEnv(options.arguments, null, new Adapter);

//will works without hacks in the next versions
var callbackDone = function () {
  debug('done run generator');
}


var cwd = process.cwd();
if (options.generatorPath) {
  process.chdir(options.generatorPath);
  //env.register(options.generatorPath, 'angular:app');
  debug('invoke run');
  //env.run('angular:app', callbackDone);
  env.lookup(function () {
    debug('invoke run');
    process.chdir(cwd);
    env.run(options.generatorName, null, callbackDone);
  });
} else if (options.generatorName) {
  env.lookup(function () {
    debug('invoke run');
    env.run(options.generatorName, null, callbackDone);
  });
} else {
  throw new Error("You should specify generatorName or generatorPath");
}
/**
 * @constructor
 */
function Adapter() {
  debug('adapter create');
  this.prompt = inquirer.createPromptModule();

  Object.keys(this.prompt.prompts).forEach(function (name) {
    this.prompt.registerPrompt(name, Prompt.bind(null, prompts.handlers[name] || prompts.defaultHandler));
  }, this);


  this.log = yeomanEnv.util.log();

}


/**
 * @constructor
 */
function Prompt(getResultFunction, question, rl, answers) {
  this.question = question;
  this.rl = rl;
  this.answers = answers;


  this.run = function (callback) {
    printMessage(question);
{'fraction_non_alphanumeric': 0.15474297827239003, 'fraction_numerical': 0.0012365306482953543, 'mean_word_length': 2.8940852819807428, 'pattern_counts': {'":': 10, '<': 13, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1291110', 'n_tokens_mistral': 1783, 'n_tokens_neox': 1737, 'n_words': 395}