<commit_before>var program = require('commander');
var testRunner = new(require(__dirname + '/testRunnerImproved.js').testRunner)();
var jsonSchema = require('jsonschema');
var validate = jsonSchema.validate;
var colors = require('colors');
var libpath = require('path'),
	fs = require('fs');

require('pretty-error').start();

program
    .version('0.0.1')
    .option('-e, --endpoint [url]', 'xAPI endpoint')
    .option('-u, --authUser [string]', 'Basic Auth Username')
    .option('-p, --authPassword [string]', 'Basic Auth Password')
    .option('-a, --basicAuth', 'Enable Basic Auth')
    .option('-o, --oAuth1', 'Enable oAuth 1')
    .option('-c, --consumer_key [string]', 'oAuth 1 Consumer Key')
    .option('-s, --consumer_secret [string]', 'oAuth 1 Consumer Secert')
    .option('-r, --request_token_path [string]', 'Path to OAuth request token endpoint (relative to endpoint)')
    .option('-t, --auth_token_path [string]', 'Path to OAuth authorization token endpoint (relative to endpoint)')
    .option('-l, --authorization_path [string]', 'Path to OAuth user authorization endpoint (relative to endpoint)')
    .parse(process.argv);

var options = {
        endpoint: program.endpoint,
        authUser: program.authUser,
        authPass: program.authPassword,
        basicAuth: program.basicAuth,
        oAuth1: program.oAuth1,
        consumer_key: program.consumer_key,
        consumer_secret: program.consumer_secret,
        request_token_path: program.request_token_path,
        auth_token_path: program.auth_token_path,
        authorization_path: program.authorization_path
    }
   
    /*

var valid = validate(options, {
    type: "object",
    properties: {
        endpoint: {
            type: "string",
            format: "uri"
        },
        authUser: {
            type: "string"
        },
        authPass: {
            type: "string"
        }
    },
    required: ["endpoint", "authPass", "authUser"]
})


if (valid.errors.length) {
    program.help();
}*/

/*testRunner.on("statusMessage", function(message) {
    if (message.action == 'log')
        console.log(colors.white.bold(message.action) + ": " + message.payload);
    if (message.action == 'test fail')
    {
        console.log(colors.red.bold(message.action) + ": " + message.payload.title);
        console.log(colors.red.bold(message.payload.message));
    }
    if (message.action == 'test pass')
        console.log(colors.green.bold(message.action) + ": " + message.payload);
    if (message.action == 'suite')
        console.log("\n" + colors.white.bold(message.action) + ": ", colors.white.bold(message.payload) + "\n");
});*/


//catches ctrl+c event
process.on('SIGINT', function() {
    console.log(colors.white('Closeing'));
	testRunner.cancel();
    process.exit();
});


process.on('exit', function() {
    console.log(colors.white('Closed'));
})

function start(options)
{
    testRunner.start(options);
	
	var interval = setInterval(function(){
		console.log(JSON.stringify(testRunner.summary));
	}.bind(this), 2000);

	testRunner.on('message', function(msg)
	{
		if(msg.action === 'log'){
			console.log(msg.payload);
		}
		else if(msg.action === 'end')
		{
			clearInterval(interval);
			console.log(JSON.stringify(testRunner.summary));
			
			// write log to file
			var cleanLog = testRunner.getCleanRecord();
			var output = JSON.stringify(cleanLog, null, '    ');
			var outPath = libpath.join(__dirname, '..', testRunner.uuid+'.log');
			fs.writeFile(outPath, output);
			console.log('Full run log written to', outPath);
		}
	});
}

if (!program.oAuth1)
	start(options);
else {

    
    var config = {};
    config.consumer_key = options.consumer_key;
    config.consumer_secret = options.consumer_secret;

    //defaults for the ADL LRS
    config.request_token_path = options.request_token_path || '/OAuth/initiate';
    config.auth_token_path = options.auth_token_path ||'/OAuth/token';
    config.authorization_path = options.authorization_path || "/../accounts/login?next=/XAPI/OAuth/authorize";

    config.endpoint = options.endpoint;
    require("./OAuth.js").auth(config, function(err, oAuth) {<commit_msg>Start putting logs into a log directory<commit_after>var program = require('commander');
var testRunner = new(require(__dirname + '/testRunnerImproved.js').testRunner)();
var jsonSchema = require('jsonschema');
var validate = jsonSchema.validate;
var colors = require('colors');
var libpath = require('path'),
	fs = require('fs');

require('pretty-error').start();

program
    .version('0.0.1')
    .option('-e, --endpoint [url]', 'xAPI endpoint')
    .option('-u, --authUser [string]', 'Basic Auth Username')
    .option('-p, --authPassword [string]', 'Basic Auth Password')
    .option('-a, --basicAuth', 'Enable Basic Auth')
    .option('-o, --oAuth1', 'Enable oAuth 1')
    .option('-c, --consumer_key [string]', 'oAuth 1 Consumer Key')
    .option('-s, --consumer_secret [string]', 'oAuth 1 Consumer Secert')
    .option('-r, --request_token_path [string]', 'Path to OAuth request token endpoint (relative to endpoint)')
    .option('-t, --auth_token_path [string]', 'Path to OAuth authorization token endpoint (relative to endpoint)')
    .option('-l, --authorization_path [string]', 'Path to OAuth user authorization endpoint (relative to endpoint)')
    .parse(process.argv);

var options = {
        endpoint: program.endpoint,
        authUser: program.authUser,
        authPass: program.authPassword,
        basicAuth: program.basicAuth,
        oAuth1: program.oAuth1,
        consumer_key: program.consumer_key,
        consumer_secret: program.consumer_secret,
        request_token_path: program.request_token_path,
        auth_token_path: program.auth_token_path,
        authorization_path: program.authorization_path
    }
   
    /*

var valid = validate(options, {
    type: "object",
    properties: {
        endpoint: {
            type: "string",
            format: "uri"
        },
        authUser: {
            type: "string"
        },
        authPass: {
            type: "string"
        }
    },
    required: ["endpoint", "authPass", "authUser"]
})


if (valid.errors.length) {
    program.help();
}*/

/*testRunner.on("statusMessage", function(message) {
    if (message.action == 'log')
        console.log(colors.white.bold(message.action) + ": " + message.payload);
    if (message.action == 'test fail')
    {
        console.log(colors.red.bold(message.action) + ": " + message.payload.title);
        console.log(colors.red.bold(message.payload.message));
    }
    if (message.action == 'test pass')
        console.log(colors.green.bold(message.action) + ": " + message.payload);
    if (message.action == 'suite')
        console.log("\n" + colors.white.bold(message.action) + ": ", colors.white.bold(message.payload) + "\n");
});*/


//catches ctrl+c event
process.on('SIGINT', function() {
    console.log(colors.white('Closeing'));
	testRunner.cancel();
    process.exit();
});


process.on('exit', function() {
    console.log(colors.white('Closed'));
})

function start(options)
{
    testRunner.start(options);
	
	var interval = setInterval(function(){
		console.log(JSON.stringify(testRunner.summary));
	}.bind(this), 2000);

	testRunner.on('message', function(msg)
	{
		if(msg.action === 'log'){
			console.log(msg.payload);
		}
		else if(msg.action === 'end')
		{
			clearInterval(interval);
			console.log(JSON.stringify(testRunner.summary));
			
			// write log to file
			var cleanLog = testRunner.getCleanRecord();
			var output = JSON.stringify(cleanLog, null, '    ');
			var outDir = libpath.join(__dirname, '../logs');
			fs.mkdir(outDir, 0o775, function(){
				var outPath = libpath.join(outDir, testRunner.uuid+'.log');
				fs.writeFile(outPath, output);
				console.log('Full run log written to', outPath);
			});
		}
	});
}

if (!program.oAuth1)
	start(options);
else {

    
    var config = {};
    config.consumer_key = options.consumer_key;
    config.consumer_secret = options.consumer_secret;

    //defaults for the ADL LRS
    config.request_token_path = options.request_token_path || '/OAuth/initiate';
    config.auth_token_path = options.auth_token_path ||'/OAuth/token';
    config.authorization_path = options.authorization_path || "/../accounts/login?next=/XAPI/OAuth/authorize";

    config.endpoint = options.endpoint;
    require("./OAuth.js").auth(config, function(err, oAuth) {
{'fraction_non_alphanumeric': 0.16425005942476825, 'fraction_numerical': 0.0038031851675778463, 'mean_word_length': 3.3287037037037037, 'pattern_counts': {'":': 8, '<': 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': '4586345', 'n_tokens_mistral': 2742, 'n_tokens_neox': 2606, 'n_words': 527}