<commit_before>/**
 * Parse command-line arguments.
 *
 * Inspects the arguments and calls the appropriate action.
 *
 * Options:
 *
 *   - `argv` {Object} is an optimist.argv object.
 *   - `[callback]` {Function} is called on completion.
 */

module.exports = function(argv, callback) {
    // optional callback
    callback = callback || function() {};

    // --version
    if (argv.version || argv.v) {
        this.version(argv, callback);
        return;
    }

    // --help
    if (argv.help || argv.h) {
        argv._.unshift('help');
    }

    // support <command> help
    if (argv._[argv._.length-1] === 'help' && argv._.length > 1) {
        argv._.pop();
        argv._.unshift('help');
    }

    // no command displays help
    if (!argv._.length) {
        argv._.unshift('help');
    }

    // execute command
    if (typeof this[argv._[0]] === 'function') {
        if (typeof this[argv._[0]][argv._[1]] === 'function') {
            this[argv._[0]][argv._[1]](argv, callback);
        }
        else {
            this[argv._[0]](argv, callback);
        }
    }
    else {
        this.unknown(argv, callback);
    }
};
<commit_msg>[doc] Clarify CLI --help handler.<commit_after>/**
 * Parse command-line arguments.
 *
 * Inspects the arguments and calls the appropriate action.
 *
 * Options:
 *
 *   - `argv` {Object} is an optimist.argv object.
 *   - `[callback]` {Function} is called on completion.
 */

module.exports = function(argv, callback) {
    // optional callback
    callback = callback || function() {};

    // --version
    if (argv.version || argv.v) {
        this.version(argv, callback);
        return;
    }

    // --help
    // --help <command>
    if (argv.help || argv.h) {
        argv._.unshift('help');
    }

    // support <command> help
    if (argv._[argv._.length-1] === 'help' && argv._.length > 1) {
        argv._.pop();
        argv._.unshift('help');
    }

    // no command displays help
    if (!argv._.length) {
        argv._.unshift('help');
    }

    // execute command
    if (typeof this[argv._[0]] === 'function') {
        if (typeof this[argv._[0]][argv._[1]] === 'function') {
            this[argv._[0]][argv._[1]](argv, callback);
        }
        else {
            this[argv._[0]](argv, callback);
        }
    }
    else {
        this.unknown(argv, callback);
    }
};

{'fraction_non_alphanumeric': 0.18208828522920203, 'fraction_numerical': 0.006791171477079796, 'mean_word_length': 1.9647798742138365, 'pattern_counts': {'":': 0, '<': 6, '<?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': '865033', 'n_tokens_mistral': 764, 'n_tokens_neox': 749, 'n_words': 166}