<commit_before>var conf = {},
    argv = require('minimist')
        (process.argv.slice(2),
          {
            'boolean': ['backfill', 'daemon']
          });

conf.include = function(inc) {
  if (Array.isArray(inc)) {
    inc.forEach(this.include, this);
  } else if (typeof inc === 'string') {
    try {
      this.process(require(inc));
    } catch (e) {
      console.log (e);
    }
  }
}

conf.process = function(argv) {
  if (!this.payload) {
    this.payload = {
      'map': {}
    };
  }
  if (!this.analyse) {
    this.analyse = {
      'pattern': []
    };
  }
  if (argv.tid) {
    this.tid = argv.tid;
  }
  if (argv.tail) {
    this.tail = Array.isArray(argv.tail) ? argv.tail : [ argv.tail ];
  }
  if (argv._) {
    for (i in argv._) {
      this.tail.push(argv._[i]);
    }
  }
  if (argv.backfill) {
    this.backfill = argv.backfill;
  }
  if (argv.daemon) {
    this.daemon = argv.daemon;
  }
  if (argv.endpoint) {
    this.endpoint = argv.endpoint;
  }
  if (argv.user) {
    this.user = argv.user;
  }
  if (argv.group) {
    this.group = argv.group;
  }
  if (argv.payload && argv.payload.map) {
    for (index in argv.payload.map) {
      this.payload.map[index] = argv.payload.map[index];
    };
  }
  if (argv.analyse && argv.analyse.pattern) {
    for (index in argv.analyse.pattern) {
      this.analyse.pattern.push(argv.analyse.pattern[index]);
    };
  }
  if (argv.include) {
    this.include(argv.include);
  }
}

conf.process(require('../conf/default'));
conf.process(argv);

console.log(conf);

if (conf.daemon) {
  require('daemon')();

  try {
    fs.writeFile('/var/run/analyticsd.pid', ''+process.pid, console.error); 
  } catch (error) {
    console.error(error);
  }
}

try {
  process.setgid(conf.group);
  process.setuid(conf.user);
} catch (e) {
  console.log('ERROR: could not set user/group.');
  console.log(e);
}

module.exports = conf;
<commit_msg>ugh lorde I need coffee<commit_after>var conf = {},
    argv = require('minimist')
        (process.argv.slice(2),
          {
            'boolean': ['backfill', 'daemon']
          });

conf.include = function(inc) {
  if (Array.isArray(inc)) {
    inc.forEach(this.include, this);
  } else if (typeof inc === 'string') {
    try {
      this.process(require(inc));
    } catch (e) {
      console.log (e);
    }
  }
}

conf.process = function(argv) {
  if (!this.payload) {
    this.payload = {
      'map': {}
    };
  }
  if (!this.analyse) {
    this.analyse = {
      'pattern': []
    };
  }
  if (argv.tid) {
    this.tid = argv.tid;
  }
  if (argv.tail) {
    this.tail = Array.isArray(argv.tail) ? argv.tail : [ argv.tail ];
  }
  if (argv._) {
    for (i in argv._) {
      this.tail.push(argv._[i]);
    }
  }
  if (argv.backfill) {
    this.backfill = argv.backfill;
  }
  if (argv.daemon) {
    this.daemon = argv.daemon;
  }
  if (argv.endpoint) {
    this.endpoint = argv.endpoint;
  }
  if (argv.user) {
    this.user = argv.user;
  }
  if (argv.group) {
    this.group = argv.group;
  }
  if (argv.payload && argv.payload.map) {
    for (index in argv.payload.map) {
      this.payload.map[index] = argv.payload.map[index];
    };
  }
  if (argv.analyse && argv.analyse.pattern) {
    for (index in argv.analyse.pattern) {
      this.analyse.pattern.push(argv.analyse.pattern[index]);
    };
  }
  if (argv.include) {
    this.include(argv.include);
  }
}

conf.process(require('../conf/default'));
conf.process(argv);

console.log(conf);

if (conf.daemon) {
  require('daemon')();

  try {
    require('fs').writeFile('/var/run/analyticsd.pid', process.pid, console.error); 
  } catch (error) {
    console.error(error);
  }
}

try {
  process.setgid(conf.group);
  process.setuid(conf.user);
} catch (e) {
  console.log('ERROR: could not set user/group.');
  console.log(e);
}

module.exports = conf;

{'fraction_non_alphanumeric': 0.18687924725561944, 'fraction_numerical': 0.0005227391531625719, 'mean_word_length': 2.420017873100983, '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': '5790719', 'n_tokens_mistral': 1445, 'n_tokens_neox': 1444, 'n_words': 240}