<commit_before>/*
 * Clifier
 * https://github.com/CapMousse/clifier
 *
 * Copyright (c) 2013 <NAME>
 * Licensed under the WTFPL license.
 */

'use strict';

var helpers = require('./helpers');

/***************************/
/********* Helpers *********/
/***************************/
String.prototype.repeat = function(count) {
    if (count < 1){
        return '';  
    } 

    var result = '', pattern = this.valueOf();

    while (count > 0) {
        if (count & 1){
            result += pattern;
        }
        count >>= 1, pattern += pattern;
    }

    return result;
};


function Argument(name, description, defaultValue, filter) {
    this._name = name;
    this._description = description;
    this._defaultValue = defaultValue;
    this._filter = filter;
}

Argument.prototype.getName = function(){
    return this._name;
};

Argument.prototype.getDescription = function(){
    return this._description || false;
};

Argument.prototype.getDefaultValue = function(){
    return this._defaultValue;
};

Argument.prototype.getFilter = function(){
    return this._filter;
};

Argument.prototype.parse = function(options) {
    var len = options.length,
        arg = this.getName().split(','),
        i = 0,
        name,
        value;

    for (; i < len; i++) {
        name = options[i][0];
        value = options[i][1] || void(0);

        if (arg.indexOf(name) === -1) {
            value = void(0);
            continue;
        }

        if (void(0) === value && null !== this.getDefaultValue()) {
            value = this.getDefaultValue();
        }

        if (typeof this.getFilter() === 'function') {
            value = this.getFilter().call(this, value);
        }

        return value;
    }

    // Argument was not called by user, try "default" value and call filter
    if (void(0) === value && null !== this.getDefaultValue()) {
        value = this.getDefaultValue();
    }

    if (typeof this.getFilter() === 'function') {
        value = this.getFilter().call(this, value);
    }

    return value;
};



function Command(name, description, exec) {
    this._name = name;
    this._description = description;
    this._function = exec;
    this._arguments = [];

    return this;
}

Command.prototype.addArgument = function(name, description, defaultValue, filter) {
    var argument;

    if ("object" === name && void(0) !== name.constructor && "Argument" === name.constructor.name){
        argument = name;
    } else {
        argument = new Argument(name, description, defaultValue, filter);
    }

    this._arguments.push(argument);

    return this;
};

Command.prototype.getArguments = function() {
    return this._arguments;
};

Command.prototype.runCommand = function(args) {
    if (typeof this.getFunction() === 'function') {
        return this.getFunction().apply(this, args);
    }

    helpers.write('The command ' + this._name + ' doesn\'t have a valid function callback.');
    return;
};

Command.prototype.getName = function(){
    return this._name;
};<commit_msg>Fix error message when command don't use a valid function callback<commit_after>/*
 * Clifier
 * https://github.com/CapMousse/clifier
 *
 * Copyright (c) 2013 <NAME>
 * Licensed under the WTFPL license.
 */

'use strict';

var helpers = require('./helpers');

/***************************/
/********* Helpers *********/
/***************************/
String.prototype.repeat = function(count) {
    if (count < 1){
        return '';  
    } 

    var result = '', pattern = this.valueOf();

    while (count > 0) {
        if (count & 1){
            result += pattern;
        }
        count >>= 1, pattern += pattern;
    }

    return result;
};


function Argument(name, description, defaultValue, filter) {
    this._name = name;
    this._description = description;
    this._defaultValue = defaultValue;
    this._filter = filter;
}

Argument.prototype.getName = function(){
    return this._name;
};

Argument.prototype.getDescription = function(){
    return this._description || false;
};

Argument.prototype.getDefaultValue = function(){
    return this._defaultValue;
};

Argument.prototype.getFilter = function(){
    return this._filter;
};

Argument.prototype.parse = function(options) {
    var len = options.length,
        arg = this.getName().split(','),
        i = 0,
        name,
        value;

    for (; i < len; i++) {
        name = options[i][0];
        value = options[i][1] || void(0);

        if (arg.indexOf(name) === -1) {
            value = void(0);
            continue;
        }

        if (void(0) === value && null !== this.getDefaultValue()) {
            value = this.getDefaultValue();
        }

        if (typeof this.getFilter() === 'function') {
            value = this.getFilter().call(this, value);
        }

        return value;
    }

    // Argument was not called by user, try "default" value and call filter
    if (void(0) === value && null !== this.getDefaultValue()) {
        value = this.getDefaultValue();
    }

    if (typeof this.getFilter() === 'function') {
        value = this.getFilter().call(this, value);
    }

    return value;
};



function Command(name, description, exec) {
    this._name = name;
    this._description = description;
    this._function = exec;
    this._arguments = [];

    return this;
}

Command.prototype.addArgument = function(name, description, defaultValue, filter) {
    var argument;

    if ("object" === name && void(0) !== name.constructor && "Argument" === name.constructor.name){
        argument = name;
    } else {
        argument = new Argument(name, description, defaultValue, filter);
    }

    this._arguments.push(argument);

    return this;
};

Command.prototype.getArguments = function() {
    return this._arguments;
};

Command.prototype.runCommand = function(args) {
    if (typeof this.getFunction() === 'function') {
        return this.getFunction().apply(this, args);
    }

    helpers.log.write'The command ' + this._name + ' doesn\'t have a valid function callback.');
    return;
};

Command.prototype.getName = function(){
    return this._name;
};
{'fraction_non_alphanumeric': 0.1693890885331591, 'fraction_numerical': 0.00555374060764456, 'mean_word_length': 2.614521841794569, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 2, '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': '5058749', 'n_tokens_mistral': 1783, 'n_tokens_neox': 1729, 'n_words': 426}