<commit_before>var
FilePath = require('filepath').FilePath,
Yargs    = require('yargs'),

Promise = require('./lib/promise'),
Objects = require('./lib/objects'),
Action  = require('./lib/action').Action,
Log     = require('./lib/log'),
LOADER  = require('./lib/loader'),
Configs = require('./lib/config_loader');


exports.main = function () {
  newUpstate().run();
};

var newUpstate = Objects.factory([Action], {

  initialize: function (args) {
    this.q(this.parseArgv);
    this.q(this.setValues);
    this.q(this.loadConfigs);
    this.q(this.initLogger);
    this.q(this.checkUser);
    this.q(this.loadTasks);
    this.q(this.checkCommand);
    this.q(this.runTask);
    this.q(this.fin);
  },

  parseArgv: function (args) {
    args.argv = Yargs
      .usage('ups <command> <task> [options]')
      .command('help', 'Print out the help text for a particular task')
      .command('run', 'Run a task')
      .command('tasks', 'Print out a list of available tasks')
      .option('h', {
        alias    : 'help',
        describe : 'Print out this help text and exit.'
      })
      .option('e', {
        alias    : 'env',
        describe : 'The environment to use.',
      })
      .argv;
    return args;
  },

  setValues: function (args) {
    args.environment = args.argv.env;
    args.directory = FilePath.create().append('upstate');
    return args;
  },

  loadConfigs: function (args) {
    return Configs.newConfigLoader().run({
      configPath  : args.directory.append('config.ini'),
      environment : args.environment
    }).then(function (configs) {
      args.config = configs.config;
      args.user_data = configs.user_data;
      return args;
    });
  },

  initLogger: function (args) {
    return Log.newLogger({
      directory : FilePath.create().append('log', 'upstate'),
      filename  : args.config.project_name
    }).then(function (api) {
      args.log = api;
      args.log.info('performing upstate run');
      args.log.stdout('Performing upstate run ...');
      return args;
    });
  },

  checkUser: function (args) {
    var
    argv = args.argv;

    if (!argv._.length && argv.help) {
      printHelpAndExit();
    } else if (!argv._.length) {
      printHelpAndExit('A command is required.');
    } else if (['help', 'run', 'tasks'].indexOf(argv._[0]) === -1) {
      printHelpAndExit('"'+ argv._[0] +'" is not a valid command');
    } else if (!argv.env) {
      printHelpAndExit('The -e --env argument must be passed.');
    }
    return args;
  },

  loadTasks: function (args) {
    return LOADER.loadTasks({
      task_directory : args.directory,<commit_msg>Check command line arguments sooner.<commit_after>var
FilePath = require('filepath').FilePath,
Yargs    = require('yargs'),

Promise = require('./lib/promise'),
Objects = require('./lib/objects'),
Action  = require('./lib/action').Action,
Log     = require('./lib/log'),
LOADER  = require('./lib/loader'),
Configs = require('./lib/config_loader');


exports.main = function () {
  newUpstate().run();
};

var newUpstate = Objects.factory([Action], {

  initialize: function (args) {
    this.q(this.parseArgv);
    this.q(this.setValues);
    this.q(this.checkArgv);
    this.q(this.loadConfigs);
    this.q(this.initLogger);
    this.q(this.loadTasks);
    this.q(this.checkCommand);
    this.q(this.runTask);
    this.q(this.fin);
  },

  parseArgv: function (args) {
    args.argv = Yargs
      .usage('ups <command> <task> [options]')
      .command('help', 'Print out the help text for a particular task')
      .command('run', 'Run a task')
      .command('tasks', 'Print out a list of available tasks')
      .option('h', {
        alias    : 'help',
        describe : 'Print out this help text and exit.'
      })
      .option('e', {
        alias    : 'env',
        describe : 'The environment to use.',
      })
      .argv;
    return args;
  },

  setValues: function (args) {
    args.environment = args.argv.env;
    args.directory = FilePath.create().append('upstate');
    return args;
  },

  checkArgv: function (args) {
    var
    argv = args.argv;

    if (!argv._.length && argv.help) {
      printHelpAndExit();
    } else if (!argv._.length) {
      printHelpAndExit('A command is required.');
    } else if (['help', 'run', 'tasks'].indexOf(argv._[0]) === -1) {
      printHelpAndExit('"'+ argv._[0] +'" is not a valid command');
    } else if (!argv.env) {
      printHelpAndExit('The -e --env argument must be passed.');
    }
    return args;
  },

  loadConfigs: function (args) {
    return Configs.newConfigLoader().run({
      configPath  : args.directory.append('config.ini'),
      environment : args.environment
    }).then(function (configs) {
      args.config = configs.config;
      args.user_data = configs.user_data;
      return args;
    });
  },

  initLogger: function (args) {
    return Log.newLogger({
      directory : FilePath.create().append('log', 'upstate'),
      filename  : args.config.project_name
    }).then(function (api) {
      args.log = api;
      args.log.info('performing upstate run');
      args.log.stdout('Performing upstate run ...');
      return args;
    });
  },

  loadTasks: function (args) {
    return LOADER.loadTasks({
      task_directory : args.directory,
{'fraction_non_alphanumeric': 0.16790264308803954, 'fraction_numerical': 0.0011409013120365088, 'mean_word_length': 2.730496453900709, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1228929', 'n_tokens_mistral': 1671, 'n_tokens_neox': 1656, 'n_words': 373}