<commit_before>var fs = require('fs')
var path = require('path')
var debug = require('debug')
var log = debug('pando:parse')
var pull = require('pull-stream')
var parseArgs = require('minimist')
var toPull = require('stream-to-pull-stream')
var split = require('split')

function help () {
  console.log(fs.readFileSync(path.join(__dirname, 'usage.txt')).toString())
  process.exit(0)
}

var configFile = path.join(process.env.HOME, '.pando/config.json')
var config = {}
try {
  config = JSON.parse(fs.readFileSync(configFile))
} catch (e) {
  log('No $HOME/.pando/config.json file found')
  log(configFile + ' not found, trying the pando directory')

  configFile = path.join(__dirname, '../config.json')
  try {
    config = JSON.parse(fs.readFileSync(configFile))
  } catch (e) {
    log(configFile + ' not found, expecting all arguments to be supplied on the comandline')
  }
}

var options = {
  alias: {
    'help': ['h']
  },
  boolean: ['local', 'public', 'headless', 'stdin', 'help', 'start-idle'],
  default: {
    'bootstrap-timeout': config['bootstrap-timeout'] || 60, // seconds
    degree: config['degree'] || 10,
    port: config['port'] || 5000,
    host: config['host'] || null,
    headless: config['headless'] || false,
    limit: 1,
    stdin: config['stdin'] || false,
    help: false,
    local: config['local'] || false,
    module: null,
    items: pull.values([]),
    'reporting-interval': 3, // seconds
    secret: config['secret'] || 'INSECURE-SECRET',
    seed: config['seed'] || null,
    'start-idle': config['start-idle'] || false
  }
}

module.exports = function (argv) {
  log('parsing: ' + argv)
  argv = parseArgs(argv, options)
  log('after minimist: ')
  log(argv)

  if (argv._.length === 0 || argv.help) {
    help()
  }

  argv.module = path.join(process.cwd(), argv._[0])
  // Try loading the module to see if it is valid
  var f = require(argv.module)
  if (!f.hasOwnProperty('/pando/1.0.0')) {
    console.log("Incompatible module, missing '/pando/1.0.0' property")
    process.exit(1)
  }<commit_msg>Reordered defaults to put them in alphabetical order<commit_after>var fs = require('fs')
var path = require('path')
var debug = require('debug')
var log = debug('pando:parse')
var pull = require('pull-stream')
var parseArgs = require('minimist')
var toPull = require('stream-to-pull-stream')
var split = require('split')

function help () {
  console.log(fs.readFileSync(path.join(__dirname, 'usage.txt')).toString())
  process.exit(0)
}

var configFile = path.join(process.env.HOME, '.pando/config.json')
var config = {}
try {
  config = JSON.parse(fs.readFileSync(configFile))
} catch (e) {
  log('No $HOME/.pando/config.json file found')
  log(configFile + ' not found, trying the pando directory')

  configFile = path.join(__dirname, '../config.json')
  try {
    config = JSON.parse(fs.readFileSync(configFile))
  } catch (e) {
    log(configFile + ' not found, expecting all arguments to be supplied on the comandline')
  }
}

var options = {
  alias: {
    'help': ['h']
  },
  boolean: ['local', 'public', 'headless', 'stdin', 'help', 'start-idle'],
  default: {
    'bootstrap-timeout': config['bootstrap-timeout'] || 60, // seconds
    degree: config['degree'] || 10,
    host: config['host'] || null,
    headless: config['headless'] || false,
    help: false,
    items: pull.values([]),
    limit: 1,
    local: config['local'] || false,
    module: null,
    port: config['port'] || 5000,
    'reporting-interval': 3, // seconds
    secret: config['secret'] || 'INSECURE-SECRET',
    seed: config['seed'] || null,
    'start-idle': config['start-idle'] || false,
    stdin: config['stdin'] || false
  }
}

module.exports = function (argv) {
  log('parsing: ' + argv)
  argv = parseArgs(argv, options)
  log('after minimist: ')
  log(argv)

  if (argv._.length === 0 || argv.help) {
    help()
  }

  argv.module = path.join(process.cwd(), argv._[0])
  // Try loading the module to see if it is valid
  var f = require(argv.module)
  if (!f.hasOwnProperty('/pando/1.0.0')) {
    console.log("Incompatible module, missing '/pando/1.0.0' property")
    process.exit(1)
  }
{'fraction_non_alphanumeric': 0.18309518043109713, 'fraction_numerical': 0.009687575684185032, 'mean_word_length': 3.7362385321100917, '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': '4375142', 'n_tokens_mistral': 1415, 'n_tokens_neox': 1394, 'n_words': 339}