<commit_before>/**
 * @fileoverview A parser for command line options.
 */

require("core/array");
require("core/string");

/**
 * Create a new command line option parser.
 */
exports.Parser = function() {
    var options = [];

    /**
     * Add an option to the parser.
     * @param shortName the short option name (without leading hyphen)
     * @param longName the long option name (without leading hyphens)
     * @param argument the name of the argument if the option requires one, or null
     * @param helpText the help text to display for the option
     */
    this.addOption = function(shortName, longName, argument, helpText) {
        if (shortName && shortName.length != 1) {
            throw new Error("Short option must be a string of length 1");
        }
        longName = longName || "";
        argument = argument || "";
        options.push({
            shortName: shortName,
            longName: longName,
            argument: argument,
            helpText: helpText
        });
    };

    /**
     * Get help text for the parser's options suitable for display in command line scripts.
     */
    this.help = function() {
        var lines = [];
        for each (var opt in options) {
            var flags = " -" + opt.shortName;
            if (opt.longName) {
                flags += " --" + opt.longName;
            }
            if (opt.argument) {
                flags += " " + opt.argument;
            }
            lines.push({flags: flags, helpText: opt.helpText});
        }
        var maxlength = lines.map(function(s) s.flags.length).max();
        return lines.map(
            function(s) s.flags.pad(" ", 2 + maxlength) + s.helpText
        ).join("\n");
    };

    /**
     * Parse an arguments array into an option object.
     * @param args the argument array. Matching options are removed.
     * @param result optional result object. If undefined, a new Object is created
     * @return the result object
     */
    this.parse = function(args, result) {
        result = result || {};
        while (args.length > 0) {
            var option = args.shortName;
            if (!option.startsWith("-")) {
                break;
            }
            if (option.startsWith("--")) {
                parseLongOption(option.substring(2), args, result);
            } else {
                parseShortOption(option.substring(1), args, result);
            }
        }
        return result;
    };

    function parseShortOption(opt, args, result) {
        var length = opt.length;
        var consumedNext = false;<commit_msg>Fix stupid typo in earlier "refactoring"<commit_after>/**
 * @fileoverview A parser for command line options.
 */

require("core/array");
require("core/string");

/**
 * Create a new command line option parser.
 */
exports.Parser = function() {
    var options = [];

    /**
     * Add an option to the parser.
     * @param shortName the short option name (without leading hyphen)
     * @param longName the long option name (without leading hyphens)
     * @param argument the name of the argument if the option requires one, or null
     * @param helpText the help text to display for the option
     */
    this.addOption = function(shortName, longName, argument, helpText) {
        if (shortName && shortName.length != 1) {
            throw new Error("Short option must be a string of length 1");
        }
        longName = longName || "";
        argument = argument || "";
        options.push({
            shortName: shortName,
            longName: longName,
            argument: argument,
            helpText: helpText
        });
    };

    /**
     * Get help text for the parser's options suitable for display in command line scripts.
     */
    this.help = function() {
        var lines = [];
        for each (var opt in options) {
            var flags = " -" + opt.shortName;
            if (opt.longName) {
                flags += " --" + opt.longName;
            }
            if (opt.argument) {
                flags += " " + opt.argument;
            }
            lines.push({flags: flags, helpText: opt.helpText});
        }
        var maxlength = lines.map(function(s) s.flags.length).max();
        return lines.map(
            function(s) s.flags.pad(" ", 2 + maxlength) + s.helpText
        ).join("\n");
    };

    /**
     * Parse an arguments array into an option object.
     * @param args the argument array. Matching options are removed.
     * @param result optional result object. If undefined, a new Object is created
     * @return the result object
     */
    this.parse = function(args, result) {
        result = result || {};
        while (args.length > 0) {
            var option = args[0];
            if (!option.startsWith("-")) {
                break;
            }
            if (option.startsWith("--")) {
                parseLongOption(option.substring(2), args, result);
            } else {
                parseShortOption(option.substring(1), args, result);
            }
        }
        return result;
    };

    function parseShortOption(opt, args, result) {
        var length = opt.length;
        var consumedNext = false;
{'fraction_non_alphanumeric': 0.1161402157164869, 'fraction_numerical': 0.0025038520801232665, 'mean_word_length': 1.8146341463414635, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3910019', 'n_tokens_mistral': 1386, 'n_tokens_neox': 1360, 'n_words': 446}