<commit_before>'use strict'

glob = require 'glob'
pathUtils = require 'path'
cp = require 'child_process'
fs = require 'fs'

[_, _, path] = process.argv

realpath = fs.realpathSync ''

runTestFile = (path) ->
	try
		require pathUtils.join realpath, path
	catch err
		console.error err

pathIsFile = pathIsDir = false
if fs.existsSync(path)
	pathStat = fs.statSync path
	pathIsFile = pathStat.isFile()
	pathIsDir = pathStat.isDirectory()

if pathIsFile
	runTestFile path
else
	if pathIsDir
		globPath = pathUtils.join path, '/', '**/*'
	else
		globPath = path

	glob globPath, (err, files) ->
		if err
			throw err

		for file in files
			runTestFile file

		return
<commit_msg>CLI now accepts '--require' option<commit_after>'use strict'

glob = require 'glob'
pathUtils = require 'path'
cp = require 'child_process'
fs = require 'fs'

[_, _, path, optsArgv...] = process.argv

realpath = fs.realpathSync ''
opts =
	require: []

# parse opts
do ->
	argv = optsArgv.splice ' '
	i = 0
	n = argv.length
	while i < n
		arg = argv[i]
		switch arg
			when '--require'
				opts.require.push argv[++i]
			else
				throw new Error "Unexpected option '#{arg}'"
		i++

runTestFile = (path) ->
	try
		require pathUtils.join realpath, path
	catch err
		console.error err

pathIsFile = pathIsDir = false

if fs.existsSync(path)
	pathStat = fs.statSync path
	pathIsFile = pathStat.isFile()
	pathIsDir = pathStat.isDirectory()

# requires
for requirePath in opts.require
	require pathUtils.join realpath, requirePath

if pathIsFile
	runTestFile path
else
	if pathIsDir
		globPath = pathUtils.join path, '/', '**/*'
	else
		globPath = path

	glob globPath, (err, files) ->
		if err
			throw err

		for file in files
			runTestFile file

		return

{'fraction_non_alphanumeric': 0.1092485549132948, 'fraction_numerical': 0.0005780346820809249, 'mean_word_length': 3.531413612565445, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 8, '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': '850760', 'n_tokens_mistral': 648, 'n_tokens_neox': 604, 'n_words': 182}