<commit_before>(function () {
    var optsClass = function (config) {
        this.config = config;
    }
    optsClass.prototype.getOpts = function () {
        var argparse = require('argparse')
        var ArgumentParser = argparse.ArgumentParser;
        var fs = require('fs');
        var optparse = new ArgumentParser({
            version: '0.0.1',
            addHelp:true,
            description: 'Quizzer, a quiz server'
        });
        optparse.addArgument(
            [ '-H', '--proxy-hostname' ],
            {
                help: 'Host name for external access'
            }
        );
        optparse.addArgument(
            [ '-Q', '--quizzer-path' ],
            {
                help: 'Server path to quizzer (default: "/quizzer/")'
            }
        );
        optparse.addArgument(
            [ '-p', '--real-port' ],
            {
                help: 'Port on which to listen for local connections'
            }
        );
        optparse.addArgument(
            [ '-e', '--email-account' ],
            {
                help: 'Full username of email account (e.g. <EMAIL>)'
            }
        );
        optparse.addArgument(
            [ '-s', '--smtp-host' ],
            {
                help: 'SMTP host name (e.g. smtp.gmail.com)'
            }
        );
        var args = optparse.parseArgs();
        if (args.real_port) {
            console.log("Reading config from quizzer-" + args.real_port + ".cfg");
            try {
                var newconfig = JSON.parse(fs.readFileSync('quizzer-' + args.real_port + '.cfg'));
                for (var key in newconfig) {
                    this.config[key] = newconfig[key];
                }
            } catch (err) {
                console.log("Warning: Error reading config file: "+err);
                //process.exit();
            }
        }
        var saveConfig = false;
        for (var key in args) {
            if (['isset','set','unset','get'].indexOf(key) > -1) continue;
            if (args[key] && this.config[key] != args[key]) {
                saveConfig = true;
                this.config[key] = args[key];
            }
        }
        // Put all opt error handling here
        var configOops = [];
        for (var key in this.config) {
            if (!this.config[key]) {
                configOops.push(key);
            }
        }
        if (configOops.length) {
            optparse.printHelp();
            for (var i=0,ilen=configOops.length;i<ilen;i+=1) {
                console.log("  ERROR: must set option "+configOops[i]);
            }
            return false;
        }
        if (saveConfig) {
            var configJson = JSON.stringify(this.config,null,2);
            fs.writeFileSync('quizzer-' + this.config.real_port + '.cfg', configJson);
            console.log("Wrote config parameters to quizzer-" + this.config.real_port + '.cfg');
            console.log("Quizzer can now be run with the single option: -p " + this.config.real_port);
        }
        // Write commenter message templates to disk if necessary
        var templates = [
            "commenter-message.txt",
            "quiz-message.txt",
            "quiz-message-past-quizzes.txt",
            "quiz-message-unanswered.txt",
            "quiz-message-answered.txt"
        ];
        for (var i=0,ilen=templates.length;i<ilen;i+=1) {
            var template = templates[i];
            fs.readFile(template,function(err) {
                if (err) {
                    var commenterMessage = fs.readFileSync(__dirname + "/../resource/" + template).toString();
                    fs.writeFileSync(template,commenterMessage);
                }
            });
        }
        return this.config;
    }
    exports.optsClass = optsClass;
})();<commit_msg>Proper chain recursion for template install<commit_after>(function () {
    var optsClass = function (config) {
        this.config = config;
    }
    optsClass.prototype.getOpts = function () {
        var argparse = require('argparse')
        var ArgumentParser = argparse.ArgumentParser;
        var fs = require('fs');
        var optparse = new ArgumentParser({
            version: '0.0.1',
            addHelp:true,
            description: 'Quizzer, a quiz server'
        });
        optparse.addArgument(
            [ '-H', '--proxy-hostname' ],
            {
                help: 'Host name for external access'
            }
        );
        optparse.addArgument(
            [ '-Q', '--quizzer-path' ],
            {
                help: 'Server path to quizzer (default: "/quizzer/")'
            }
        );
        optparse.addArgument(
            [ '-p', '--real-port' ],
            {
                help: 'Port on which to listen for local connections'
            }
        );
        optparse.addArgument(
            [ '-e', '--email-account' ],
            {
                help: 'Full username of email account (e.g. <EMAIL>)'
            }
        );
        optparse.addArgument(
            [ '-s', '--smtp-host' ],
            {
                help: 'SMTP host name (e.g. smtp.gmail.com)'
            }
        );
        var args = optparse.parseArgs();
        if (args.real_port) {
            console.log("Reading config from quizzer-" + args.real_port + ".cfg");
            try {
                var newconfig = JSON.parse(fs.readFileSync('quizzer-' + args.real_port + '.cfg'));
                for (var key in newconfig) {
                    this.config[key] = newconfig[key];
                }
            } catch (err) {
                console.log("Warning: Error reading config file: "+err);
                //process.exit();
            }
        }
        var saveConfig = false;
        for (var key in args) {
            if (['isset','set','unset','get'].indexOf(key) > -1) continue;
            if (args[key] && this.config[key] != args[key]) {
                saveConfig = true;
                this.config[key] = args[key];
            }
        }
        // Put all opt error handling here
        var configOops = [];
        for (var key in this.config) {
            if (!this.config[key]) {
                configOops.push(key);
            }
        }
        if (configOops.length) {
            optparse.printHelp();
            for (var i=0,ilen=configOops.length;i<ilen;i+=1) {
                console.log("  ERROR: must set option "+configOops[i]);
            }
            return false;
        }
        if (saveConfig) {
            var configJson = JSON.stringify(this.config,null,2);
            fs.writeFileSync('quizzer-' + this.config.real_port + '.cfg', configJson);
            console.log("Wrote config parameters to quizzer-" + this.config.real_port + '.cfg');
            console.log("Quizzer can now be run with the single option: -p " + this.config.real_port);
        }
        // Write commenter message templates to disk if necessary
        var templates = [
            "commenter-message.txt",
            "quiz-message.txt",
            "quiz-message-past-quizzes.txt",
            "quiz-message-unanswered.txt",
            "quiz-message-answered.txt"
        ];
        installTemplates(0,templates.length);
        function installTemplates (pos,limit) {
            if (pos === limit) {
                return;
            }
            var template = templates[i];
            fs.readFile(template,function(err) {
                if (err) {
                    var commenterMessage = fs.readFileSync(__dirname + "/../resource/" + template).toString();
                    fs.writeFileSync(template,commenterMessage);
                }
                installTemplates(pos+1,limit);
            });
        }
        return this.config;
    }
    exports.optsClass = optsClass;
})();
{'fraction_non_alphanumeric': 0.13113911031113396, 'fraction_numerical': 0.0023142195937258937, 'mean_word_length': 1.4046367851622874, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 7, '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': '3768844', 'n_tokens_mistral': 2190, 'n_tokens_neox': 2122, 'n_words': 461}