<commit_before>// # app.js

var _ = require('underscore'),
    path = require("path"),
    fs   = require("fs"),
    util = require("util"),
    feather = require("./feather"),
    featherConfig = require("feather-config"),
    cluster = require('cluster'),
    os = require('os');

/* ------------------------------------------------------------------ */

// Initialize the directory structure and name of the application.
if (fs.existsSync(appDir + '/app.js')) {
  appHooks = require(appDir + "/app.js");
} 

var appDir = process.cwd();
var appName = path.basename(appDir);
var appLibDir = path.join(appDir, 'lib');
var libDir = path.join(process.env.FEATHER_HOME, 'lib');

featherConfig.init({

  appDir: appDir,
  defaultConfigPath: libDir + '/config.json',
  defaultOptionsHook: function(defaultOptions) {
    defaultOptions.featherRoot = process.env.FEATHER_HOME + "/lib";
    defaultOptions.appRoot = appDir;
    defaultOptions.daemon.outputPath = appDir + "/" + appName + ".out";
    defaultOptions.daemon.pidPath = '/tmp/' + appName + '.pid';
  },
  commandLineArgsHook: function(arg, remainingArgs, cmdLineOptions) {
    switch(arg) {
      case "env": 
        // ignore this, as it is taken care of in feather-config, but chew it up so we don't get unrecognized option warnings.
        remainingArgs.shift();
        break;
      case(appDir):
        break;
      case "daemonize": 
        if (!cmdLineOptions.daemon) cmdLineOptions.daemon = {};
        cmdLineOptions.daemon.runAsDaemon = true;
        break;
      case "outputpath":
        if (!cmdLineOptions.daemon) cmdLineOptions.daemon = {};
        cmdLineOptions.daemon.outputPath = remainingArgs.shift();
        break;
      case "pidpath":
        if (!cmdLineOptions.daemon) cmdLineOptions.daemon = {};
        cmdLineOptions.daemon.pidPath = remainingArgs.shift();
        break;
      case "loglevel":
        var level = remainingArgs.shift();
        cmdLineOptions.logging = {
          enabled: (level !== "off"),
          defaultLevel: level
        };
        break;
      case "test/unit":
        console.log("Initiating unit testing.");
        cmdLineOptions.testing = true;
        break;
      case "extras":
        var extras = remainingArgs.shift();
        cmdLineOptions.extras = extras;
        break;
      default:
        console.warn("Unrecognized option: " + arg);
        break;
    } // end switch
  }

}, function(err, config) {

  if (process.argv[1] === "debug") {
    console.info("Final config hierarchy: " + config.dumpBuildInfo());
    console.info("Final config: " + util.inspect(config));<commit_msg>enabling debug now displays config breadcrumb and final rendered config in console.<commit_after>// # app.js

var _ = require('underscore'),
    path = require("path"),
    fs   = require("fs"),
    util = require("util"),
    feather = require("./feather"),
    featherConfig = require("feather-config"),
    cluster = require('cluster'),
    os = require('os');

/* ------------------------------------------------------------------ */

// Initialize the directory structure and name of the application.
if (fs.existsSync(appDir + '/app.js')) {
  appHooks = require(appDir + "/app.js");
} 

var appDir = process.cwd();
var appName = path.basename(appDir);
var appLibDir = path.join(appDir, 'lib');
var libDir = path.join(process.env.FEATHER_HOME, 'lib');

featherConfig.init({

  appDir: appDir,
  defaultConfigPath: libDir + '/config.json',
  defaultOptionsHook: function(defaultOptions) {
    defaultOptions.featherRoot = process.env.FEATHER_HOME + "/lib";
    defaultOptions.appRoot = appDir;
    defaultOptions.daemon.outputPath = appDir + "/" + appName + ".out";
    defaultOptions.daemon.pidPath = '/tmp/' + appName + '.pid';
  },
  commandLineArgsHook: function(arg, remainingArgs, cmdLineOptions) {
    switch(arg) {
      case "env": 
        // ignore this, as it is taken care of in feather-config, but chew it up so we don't get unrecognized option warnings.
        remainingArgs.shift();
        break;
      case(appDir):
        break;
      case "daemonize": 
        if (!cmdLineOptions.daemon) cmdLineOptions.daemon = {};
        cmdLineOptions.daemon.runAsDaemon = true;
        break;
      case "outputpath":
        if (!cmdLineOptions.daemon) cmdLineOptions.daemon = {};
        cmdLineOptions.daemon.outputPath = remainingArgs.shift();
        break;
      case "pidpath":
        if (!cmdLineOptions.daemon) cmdLineOptions.daemon = {};
        cmdLineOptions.daemon.pidPath = remainingArgs.shift();
        break;
      case "loglevel":
        var level = remainingArgs.shift();
        cmdLineOptions.logging = {
          enabled: (level !== "off"),
          defaultLevel: level
        };
        break;
      case "test/unit":
        console.log("Initiating unit testing.");
        cmdLineOptions.testing = true;
        break;
      case "extras":
        var extras = remainingArgs.shift();
        cmdLineOptions.extras = extras;
        break;
      default:
        console.warn("Unrecognized option: " + arg);
        break;
    } // end switch
  }

}, function(err, config) {
  if (!err && _.contains(process.execArgv, '--debug-brk')) {
    console.info("Final config hierarchy: " + config.dumpBuildInfo());
    console.info("Final config: " + JSON.stringify(config));
{'fraction_non_alphanumeric': 0.16069082034916463, 'fraction_numerical': 0.00018772292096865028, 'mean_word_length': 2.5449101796407185, 'pattern_counts': {'":': 14, '<': 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': '1003470', 'n_tokens_mistral': 1563, 'n_tokens_neox': 1539, 'n_words': 353}