<commit_before>/*
 * Optics / command.js
 * copyright (c) 2016 Susisu
 */

/**
 * @module command
 */

"use strict";

function endModule() {
    module.exports = Object.freeze({
        Argument,
        OptionalArgument,
        CommandBase,
        Command
    });
}

/**
 * An instance of the `Argument` class represents a (required) argument of command.
 * @static
 */
class Argument {
    /**
     * Creates a new `Argument` instance.
     * @param {string} name A string used in placeholder.
     * @param {Function} reader A function which reads value given as argument.
     * @throws {TypeError} `name` is not a string.
     * @throws {TypeError} `reader` is not a function.
     */
    constructor(name, reader) {
        if (typeof name !== "string") {
            throw new TypeError("name must be a string");
        }
        if (typeof reader !== "function") {
            throw new TypeError("reader must be a function");
        }
        this.name   = name;
        this.reader = reader;
    }

    /**
     * Returns if the argument is required.
     * This returns always `true` (i.e. an instance of `Argument` is always required).
     * @returns {boolean} `true`.
     */
    isRequired() {
        return true;
    }

    /**
     * Returns a string which is used as a placeholder in command description.
     * @returns {string} A string which is used as a placeholder.
     */
    toPlaceholder() {
        return `<${this.name}>`;
    }

    /**
     * Returns the default value, which is used when the argument is not specified.
     * @throws {Error} No default value for a required argument.
     */
    getDefaultValue() {
        throw new Error("No default value");
    }
}

/**
 * An instance of the `OptionalArgument` class represents an optional argument of command with a default value.
 * @static
 * @extends {module:command.Argument}
 */
class OptionalArgument extends Argument {
    /**
     * Creates a new `OptionalArgument` instance.
     * @param {string} name A string used in placeholder.
     * @param defaultVal The default value, which is used when the argument is not specified.
     * @param {Function} reader A function which reads value given as argument.
     * @throws {Error} `name` is not a string.
     * @throws {Error} `reader` is not a function.
     */
    constructor(name, defaultVal, reader) {
        super(name, reader);
        this.defaultVal = defaultVal;
    }

    /**
     * Returns if the argument is required.
     * This returns always `false` (i.e. an instance of `OptionalArgument` is always not required).
     * @returns {boolean} `false`.
     */
    isRequired() {
        return false;
    }

    /**
     * Returns a string which is used as a placeholder in command description.
     * @returns {string} A string which is used as a placeholder.
     */
    toPlaceholder() {
        return `[${this.name}]`;
    }

    /**
     * Returns the default value, which is used when the argument is not specified.
     * @returns The default value specified at the constructor.
     */
    getDefaultValue() {
        return this.defaultVal;
    }
}
<commit_msg>Modify doc comments for Argument#isRequired() and OptionalArgument#isRequired()<commit_after>/*
 * Optics / command.js
 * copyright (c) 2016 Susisu
 */

/**
 * @module command
 */

"use strict";

function endModule() {
    module.exports = Object.freeze({
        Argument,
        OptionalArgument,
        CommandBase,
        Command
    });
}

/**
 * An instance of the `Argument` class represents a (required) argument of command.
 * @static
 */
class Argument {
    /**
     * Creates a new `Argument` instance.
     * @param {string} name A string used in placeholder.
     * @param {Function} reader A function which reads value given as argument.
     * @throws {TypeError} `name` is not a string.
     * @throws {TypeError} `reader` is not a function.
     */
    constructor(name, reader) {
        if (typeof name !== "string") {
            throw new TypeError("name must be a string");
        }
        if (typeof reader !== "function") {
            throw new TypeError("reader must be a function");
        }
        this.name   = name;
        this.reader = reader;
    }

    /**
     * Returns whether the argument is required.
     * This method always returns `true` (i.e. an instance of `Argument` is always required).
     * @returns {boolean} `true`.
     */
    isRequired() {
        return true;
    }

    /**
     * Returns a string which is used as a placeholder in command description.
     * @returns {string} A string which is used as a placeholder.
     */
    toPlaceholder() {
        return `<${this.name}>`;
    }

    /**
     * Returns the default value, which is used when the argument is not specified.
     * @throws {Error} No default value for a required argument.
     */
    getDefaultValue() {
        throw new Error("No default value");
    }
}

/**
 * An instance of the `OptionalArgument` class represents an optional argument of command with a default value.
 * @static
 * @extends {module:command.Argument}
 */
class OptionalArgument extends Argument {
    /**
     * Creates a new `OptionalArgument` instance.
     * @param {string} name A string used in placeholder.
     * @param defaultVal The default value, which is used when the argument is not specified.
     * @param {Function} reader A function which reads value given as argument.
     * @throws {Error} `name` is not a string.
     * @throws {Error} `reader` is not a function.
     */
    constructor(name, defaultVal, reader) {
        super(name, reader);
        this.defaultVal = defaultVal;
    }

    /**
     * Returns whether the argument is required.
     * This method always returns `false` (i.e. an instance of `OptionalArgument` is always not required).
     * @returns {boolean} `false`.
     */
    isRequired() {
        return false;
    }

    /**
     * Returns a string which is used as a placeholder in command description.
     * @returns {string} A string which is used as a placeholder.
     */
    toPlaceholder() {
        return `[${this.name}]`;
    }

    /**
     * Returns the default value, which is used when the argument is not specified.
     * @returns The default value specified at the constructor.
     */
    getDefaultValue() {
        return this.defaultVal;
    }
}

{'fraction_non_alphanumeric': 0.1080741438894125, 'fraction_numerical': 0.0012566760917373547, 'mean_word_length': 2.3317634746206175, 'pattern_counts': {'":': 0, '<': 5, '<?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': '601695', 'n_tokens_mistral': 1729, 'n_tokens_neox': 1706, 'n_words': 674}