<commit_before>#!/usr/bin/env node

/*
 * meteor-deployment-manager
 * https://github.com/chriswessels/meteor-deployment-manager
 *
 * Copyright (c) 2013 <NAME>
 * Licensed under the MIT license.
 */

'use strict';

var mdm = {};

var packageJson = require('../package.json');
var VERSION = packageJson.version;

mdm.requires = {
  child: require('child_process'),
  ssh2: require('ssh2'),
  prompt: require('prompt'),
  underscore: require('underscore'),
  winston: require('winston'),
  fs: require('fs')
};
var _ = mdm.requires.underscore;
var logger = mdm.logger = mdm.requires.winston;

logger.info("Meteor Deployment Manager v" + VERSION + " loading at " + new Date().toString() + "...");

mdm.cmdArgs = {};

mdm.cmdArgs.allowed = {
  '--help,-h': {
    help: 'Use this argument to print out this help text.',
    option: 'help'
  },
  '--verbose,-v': {
    help: 'Use this argument for verbose logging to the console.',
    option: 'verbose'
  },
  '--project-path,-p': {
    help: "The path to your project. If not specified, the current working directory will be assumed.",
    option: 'projectPath'
  },
  '--config-file,-c': {
    help: 'The file name of your deployment configuration file. Defaults to deploy.json.',
    option: 'configFilename'
  }
};

mdm.cmdArgs.provided = {
  engine: process.argv[0],
  path: process.argv[1],
  user: process.argv.slice(2)
};

mdm.exitProcess = function () {
  if (VERBOSE) { logger.info('Meteor Deployment Manager exiting at ' + new Date().toString() + '.'); }
  process.exit();
};

mdm.processConfig = function (unprocessedConfig) {
  try {
    logger.info(unprocessedConfig);
  } catch (exception) {
    logger.error('An exception was encountered when attempting to process ' + configFilename + '.');
    logger.error('Error:', exception.message);
    mdm.exitProcess();
  }
};

mdm.processCmdArgs = function () {
  var allAllowed = [];
  var cmdOptions = {};
  var allAllowedGrouped = _.map(_.keys(mdm.cmdArgs.allowed), function (value, index, collection) {
    var output = {};
    var args = (value.indexOf(',') !== -1) ? value.split(',') : [value];
    output[value] = args;
    allAllowed = allAllowed.concat(args);
    return output;
  }).forEach(function (value, index, collection) {
    var key = Object.keys(value)[0];
    var intersect = _.intersection(mdm.cmdArgs.provided.user, value[key]);
    if (intersect.length > 0){
      var followingArgs = [];
      var brake = false;
      var i = false;
      while (brake === false){
        if (i === false){
          i = mdm.cmdArgs.provided.user.indexOf(intersect[0]);
        }
        i++;
        if (i > mdm.cmdArgs.provided.user.length){
          brake = true;
        }
        var nextArg = mdm.cmdArgs.provided.user[i];
        if (allAllowed.indexOf(nextArg) !== -1){
          brake = true;
        } else {
          followingArgs.push(nextArg);
        }
      }
      cmdOptions[mdm.cmdArgs.allowed[key].option] = _.compact(followingArgs);
    }
  });
  return cmdOptions;
}

mdm.cmdOptions = mdm.processCmdArgs();

var VERBOSE = mdm.cmdOptions.verbose;

if (VERBOSE) {
  logger.info("Parsed command line input:", mdm.cmdOptions);
  logger.info("Loaded in directory:", process.cwd());
}

if (mdm.cmdOptions.help) {
  logger.info("================================");
  mdm.exitProcess();
}

var configFilename = mdm.cmdOptions.configFilename ? mdm.cmdOptions.configFilename[0] : 'deploy.json';

var projectConfigPath = mdm.cmdOptions.projectPath ? mdm.cmdOptions.projectPath[0] + "/" + configFilename || process.cwd() + "/" + configFilename : process.cwd() + "/" + configFilename;

if (VERBOSE) { logger.info('Deployment configuration file path:', projectConfigPath); }

mdm.requires.fs.exists(projectConfigPath, function (exists) {
  if (VERBOSE) { logger.info('Checking for existence of ' + configFilename + '...', exists); }
  if (!exists){
    logger.error('Deployment configuration file not found at:', projectConfigPath);
    mdm.exitProcess();
  }
  if (VERBOSE) { logger.info('Now parsing ' + configFilename + '...'); }
  try {
    var unprocessedConfig = require(projectConfigPath);
  } catch (exception) {
    logger.error('An exception was encountered when attempting to require ' + configFilename + '.');
    logger.error('Error:', exception.message);
    mdm.exitProcess();
  }
  var projectConfiguration = processConfig(unprocessedConfig);
});

// var projectConfiguration = require(projectConfigPath);

// var defaultEnvironment = 'staging';
<commit_msg>Expanded help function to print out commands and associated help text.<commit_after>#!/usr/bin/env node

/*
 * meteor-deployment-manager
 * https://github.com/chriswessels/meteor-deployment-manager
 *
 * Copyright (c) 2013 <NAME>
 * Licensed under the MIT license.
 */

'use strict';

var mdm = {};

var packageJson = require('../package.json');
var VERSION = packageJson.version;

mdm.requires = {
  child: require('child_process'),
  ssh2: require('ssh2'),
  prompt: require('prompt'),
  underscore: require('underscore'),
  winston: require('winston'),
  fs: require('fs')
};
var _ = mdm.requires.underscore;
var logger = mdm.logger = mdm.requires.winston;

logger.info("Meteor Deployment Manager v" + VERSION + " loading at " + new Date().toString() + "...");

mdm.cmdArgs = {};

mdm.cmdArgs.allowed = {
  '--help,-h': {
    help: 'Use this argument to print out this help text.',
    option: 'help'
  },
  '--verbose,-v': {
    help: 'Use this argument for verbose logging to the console.',
    option: 'verbose'
  },
  '--project-path,-p': {
    help: "The path to your project. If not specified, the current working directory will be assumed.",
    option: 'projectPath'
  },
  '--config-file,-c': {
    help: 'The file name of your deployment configuration file. Defaults to deploy.json.',
    option: 'configFilename'
  }
};

mdm.cmdArgs.provided = {
  engine: process.argv[0],
  path: process.argv[1],
  user: process.argv.slice(2)
};

mdm.exitProcess = function () {
  if (VERBOSE) { logger.info('Meteor Deployment Manager exiting at ' + new Date().toString() + '.'); }
  process.exit();
};

mdm.processConfig = function (unprocessedConfig) {
  try {
    logger.info(unprocessedConfig);
  } catch (exception) {
    logger.error('An exception was encountered when attempting to process ' + configFilename + '.');
    logger.error('Error:', exception.message);
    mdm.exitProcess();
  }
};

mdm.processCmdArgs = function () {
  var allAllowed = [];
  var cmdOptions = {};
  var allAllowedGrouped = _.map(_.keys(mdm.cmdArgs.allowed), function (value, index, collection) {
    var output = {};
    var args = (value.indexOf(',') !== -1) ? value.split(',') : [value];
    output[value] = args;
    allAllowed = allAllowed.concat(args);
    return output;
  }).forEach(function (value, index, collection) {
    var key = Object.keys(value)[0];
    var intersect = _.intersection(mdm.cmdArgs.provided.user, value[key]);
    if (intersect.length > 0){
      var followingArgs = [];
      var brake = false;
      var i = false;
      while (brake === false){
        if (i === false){
          i = mdm.cmdArgs.provided.user.indexOf(intersect[0]);
        }
        i++;
        if (i > mdm.cmdArgs.provided.user.length){
          brake = true;
        }
        var nextArg = mdm.cmdArgs.provided.user[i];
        if (allAllowed.indexOf(nextArg) !== -1){
          brake = true;
        } else {
          followingArgs.push(nextArg);
        }
      }
      cmdOptions[mdm.cmdArgs.allowed[key].option] = _.compact(followingArgs);
    }
  });
  return cmdOptions;
}

mdm.cmdOptions = mdm.processCmdArgs();

var VERBOSE = mdm.cmdOptions.verbose;

if (VERBOSE) {
  logger.info("Parsed command line input:", mdm.cmdOptions);
  logger.info("Loaded in directory:", process.cwd());
}

if (mdm.cmdOptions.help) {
  logger.info("================================");
  _(mdm.cmdArgs.allowed).map(function (value, index, collection) {
    logger.info(("Command(s): " + index.replace(',', ', ')));
    logger.info(value.help);
  });
  logger.info("================================");
  mdm.exitProcess();
}

var configFilename = mdm.cmdOptions.configFilename ? mdm.cmdOptions.configFilename[0] : 'deploy.json';

var projectConfigPath = mdm.cmdOptions.projectPath ? mdm.cmdOptions.projectPath[0] + "/" + configFilename || process.cwd() + "/" + configFilename : process.cwd() + "/" + configFilename;

if (VERBOSE) { logger.info('Deployment configuration file path:', projectConfigPath); }

mdm.requires.fs.exists(projectConfigPath, function (exists) {
  if (VERBOSE) { logger.info('Checking for existence of ' + configFilename + '...', exists); }
  if (!exists){
    logger.error('Deployment configuration file not found at:', projectConfigPath);
    mdm.exitProcess();
  }
  if (VERBOSE) { logger.info('Now parsing ' + configFilename + '...'); }
  try {
    var unprocessedConfig = require(projectConfigPath);
  } catch (exception) {
    logger.error('An exception was encountered when attempting to require ' + configFilename + '.');
    logger.error('Error:', exception.message);
    mdm.exitProcess();
  }
  var projectConfiguration = processConfig(unprocessedConfig);
});

// var projectConfiguration = require(projectConfigPath);

// var defaultEnvironment = 'staging';

{'fraction_non_alphanumeric': 0.16947322970639034, 'fraction_numerical': 0.0034542314335060447, 'mean_word_length': 3.52392578125, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 2, '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': '2954103', 'n_tokens_mistral': 2956, 'n_tokens_neox': 2894, 'n_words': 662}