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

// Load the basic Geddy toolkit
require('../lib/geddy');

var fs = require('fs')
  , exec = require('child_process').exec
  , parseopts = require('../lib/parseopts')
  , utils = require('../lib/utils/index')
  , App = require('../lib/app.js').App
  , parser
  , args = process.argv.slice(2)
  , optsReg
  , cmds
  , opts
  , usage
  , cmd;

usage = ''
    + 'Geddy web framework for Node.js\n'
    + '*********************************************************************************************\n'
    + 'With no flags, server starts running on port 4000, accepting requests from http://localhost.\n'
    + '*********************************************************************************************\n'
    + '{Usage}: xdr-proxy [options]\n'
    + '\n'
    + '{Options}:\n'
    + '  -e, --environment          Evironment config to use\n'
    + '  -o, --origins HOSTNAME      Allow requests from HOSTNAME (should include protocol)\n'
    + '  -p, --port NUM             Port number, defaults to 4000\n'
    + '  -n, --workers NUM          Number of worker processes to use, defaults to 2\n'
    + '  -h, --help                 Outputs help information\n'
    + '';

optsReg = [
  { full: 'origins'
  , abbr: 'o'
  }
, { full: 'port'
  , abbr: 'p'
  }
, { full: 'workers'
  , abbr: 'n'
  }
, { full: 'version'
  , abbr: 'V'
  }
, { full: 'help'
  , abbr: 'h'
  }
, { full: 'debug'
  , abbr: 'd'
  }
, { full: 'logLevel'
  , abbr: 'l'
}
, { full: 'environment'
  , abbr: 'e'
  }
, { full: 'spawned'
  , abbr: 'Q'
  }
];

parser = new parseopts.Parser(optsReg);
parser.parse(args);
cmds = parser.cmds;
opts = parser.opts;

var start = function () {

  var cluster
    , master
    , worker
    , m
    , w
    , app;

  // Node 0.6
  try {
    cluster = require('cluster');
    geddy.FD_HACK = false;
    master = require('../lib/cluster/master')
    worker = require('../lib/cluster/worker');
  }
  // Node 0.4
  catch (e) {
    geddy.FD_HACK = true;
    master = require('../lib/cluster/hack_master')
    worker = require('../lib/cluster/hack_worker');
  }

  // Master-process
  if ((cluster && cluster.isMaster) ||
      (geddy.FD_HACK && !opts.spawned)) {
    m = new master.Master();
    m.start(opts);
  }
  // Worker-process -- start up an app
  else {
    w = new worker.Worker();
    geddy.worker = w;
    w.init(function () {
      geddy.mixin(geddy, w);
      app = new App();
      app.init(function () {
        w.startServer();
        geddy.mixin(geddy, app);
      });
    });
  }

};

if (typeof opts.help != 'undefined') {
  m.die(usage);
}
else {
  // `geddy app foo` or `geddy resource bar` etc. -- run generators
  if (cmds.length) {
    cmd = 'jake -t -f /' + __dirname + '/../Jakefile ';
    if (cmds[0] != 'secret' && !cmds[1]) {
      throw new Error(cmds[0] + ' command requires another argument.');
    }
    switch (cmds[0]) {
      case 'app':
        cmd += 'gen:app[' + cmds[1] + ']';
        break;
      case 'resource':
        cmd += 'gen:resource[' + cmds[1] + ']';
        break;
      case 'controller':
        cmd += 'gen:bareController[' + cmds[1] + ']';
        break;
      case 'secret':
        cmd += 'gen:secret';
        break;
      default:
        m.die(cmds[0] + ' is not a Geddy command.');
    }
    cmd += ' generator=true'
    exec(cmd, function (err, stdout, stderr) {
      if (err) {
        throw err;
      }
      else if (stderr) {
        console.log(stderr);
      }
      else {
        console.log(utils.string.trim(stdout));
      }
    });
  }
  // Just `geddy` -- start the server
  else {
    start();
  }
}


<commit_msg>`die` is a local command.<commit_after>#!/usr/bin/env node

// Load the basic Geddy toolkit
require('../lib/geddy');

var fs = require('fs')
  , exec = require('child_process').exec
  , parseopts = require('../lib/parseopts')
  , utils = require('../lib/utils/index')
  , App = require('../lib/app.js').App
  , parser
  , args = process.argv.slice(2)
  , optsReg
  , cmds
  , opts
  , usage
  , cmd;

usage = ''
    + 'Geddy web framework for Node.js\n'
    + '*********************************************************************************************\n'
    + 'With no flags, server starts running on port 4000, accepting requests from http://localhost.\n'
    + '*********************************************************************************************\n'
    + '{Usage}: xdr-proxy [options]\n'
    + '\n'
    + '{Options}:\n'
    + '  -e, --environment          Evironment config to use\n'
    + '  -o, --origins HOSTNAME      Allow requests from HOSTNAME (should include protocol)\n'
    + '  -p, --port NUM             Port number, defaults to 4000\n'
    + '  -n, --workers NUM          Number of worker processes to use, defaults to 2\n'
    + '  -h, --help                 Outputs help information\n'
    + '';

optsReg = [
  { full: 'origins'
  , abbr: 'o'
  }
, { full: 'port'
  , abbr: 'p'
  }
, { full: 'workers'
  , abbr: 'n'
  }
, { full: 'version'
  , abbr: 'V'
  }
, { full: 'help'
  , abbr: 'h'
  }
, { full: 'debug'
  , abbr: 'd'
  }
, { full: 'logLevel'
  , abbr: 'l'
}
, { full: 'environment'
  , abbr: 'e'
  }
, { full: 'spawned'
  , abbr: 'Q'
  }
];

parser = new parseopts.Parser(optsReg);
parser.parse(args);
cmds = parser.cmds;
opts = parser.opts;

var die = function (str) {
  console.log(str);
  process.exit();
};

var start = function () {

  var cluster
    , master
    , worker
    , m
    , w
    , app;

  // Node 0.6
  try {
    cluster = require('cluster');
    geddy.FD_HACK = false;
    master = require('../lib/cluster/master')
    worker = require('../lib/cluster/worker');
  }
  // Node 0.4
  catch (e) {
    geddy.FD_HACK = true;
    master = require('../lib/cluster/hack_master')
    worker = require('../lib/cluster/hack_worker');
  }

  // Master-process
  if ((cluster && cluster.isMaster) ||
      (geddy.FD_HACK && !opts.spawned)) {
    m = new master.Master();
    m.start(opts);
  }
  // Worker-process -- start up an app
  else {
    w = new worker.Worker();
    geddy.worker = w;
    w.init(function () {
      geddy.mixin(geddy, w);
      app = new App();
      app.init(function () {
        w.startServer();
        geddy.mixin(geddy, app);
      });
    });
  }

};

if (typeof opts.help != 'undefined') {
  die(usage);
}
else {
  // `geddy app foo` or `geddy resource bar` etc. -- run generators
  if (cmds.length) {
    cmd = 'jake -t -f /' + __dirname + '/../Jakefile ';
    if (cmds[0] != 'secret' && !cmds[1]) {
      throw new Error(cmds[0] + ' command requires another argument.');
    }
    switch (cmds[0]) {
      case 'app':
        cmd += 'gen:app[' + cmds[1] + ']';
        break;
      case 'resource':
        cmd += 'gen:resource[' + cmds[1] + ']';
        break;
      case 'controller':
        cmd += 'gen:bareController[' + cmds[1] + ']';
        break;
      case 'secret':
        cmd += 'gen:secret';
        break;
      default:
        die(cmds[0] + ' is not a Geddy command.');
    }
    cmd += ' generator=true'
    exec(cmd, function (err, stdout, stderr) {
      if (err) {
        throw err;
      }
      else if (stderr) {
        console.log(stderr);
      }
      else {
        console.log(utils.string.trim(stdout));
      }
    });
  }
  // Just `geddy` -- start the server
  else {
    start();
  }
}



{'fraction_non_alphanumeric': 0.22596481658257195, 'fraction_numerical': 0.006000272739669985, 'mean_word_length': 2.180398959236774, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3452078', 'n_tokens_mistral': 2629, 'n_tokens_neox': 2580, 'n_words': 594}