<commit_before>/**
 * Executes a module (indicated by an option) in an asynchronous way (using async.series). After the execution a
 * callback function is called. This function print, using console.log(), the result of the module execution.
 *
 * Legal options are:
 *      -) -d (or --download) for downloading the plugin. You must specify the url of the plugin.
 *      -) -u (or --update) for updating the plugin. You must specify the url of the plugin.
 *      -) -r (or --remove) for removing the plugin. You must specify the url of the plugin.
 *      -) -n (or --run) for executing the plugin. You must specify the url of the plugin.
 * Each plugin can provide a lot of modules: since each module is stored in a directory named as the module
 * itself you must also specify this name. Please, use the -m (or --module) option for this.
 * And, you know, each module can (and generally) have a lot of parameters. You have to specify these parameters if the
 * module requires it. You must provide only the values of these parameters, and you must do it in this way:
 *      -) -p (or --parameters) "list of comma separated values"
 * Please take note that -m and -p options are illegal used with -d, -u and -r, and you will get an error if you use
 * these combinations.
 *
 * Created by matteo on 20/02/16.
 */
/// <reference path="../Module/dl_plugin.ts" />
/// <reference path="../Module/rm_plugin.ts" />
/// <reference path="../Module/up_plugin.ts" />
/// <reference path="../Module/run_plugin.ts" />
var options = {
    d: 'd',
    u: 'u',
    n: 'n',
    r: 'r'
};
var async = require("async");
var getopt = require('posix-getopt');
var parser, option;
var command, module, plugin;
var args;
var error = false;
parser = new getopt.BasicParser('d:(download)r:(remove)n:(run)u:(upload)m:(module)p:(parameters)', process.argv);
while ((option = parser.getopt()) !== undefined) {
    switch (option.option) {
        case options.d:
            command = options.d;
            plugin = option.optarg;
            break;
        case options.r:
            command = options.r;
            plugin = option.optarg;
            break;
        case options.n:
            command = options.n;
            plugin = option.optarg;
            if (error) {
                error = false;
            }
            break;
        case options.u:
            command = options.u;
            plugin = option.optarg;
            break;
        case 'm':
            if (command != options.n) {
                error = true;
            }
            else {
                module = option.optarg;
            }
            break;
        case 'p':
            if (command != options.n) {
                error = true;
            }
            else {
                args = option.optarg.toString().split(',');
            }
    }
}
// Call in asynchronous way the module.
if (!error) {
    async.series([
        function (callback) {
            switch (command) {
                case options.d:
                    callback(Module.downloadPlugin(plugin));
                    break;
                case options.r:
                    callback(Module.removePlugin(plugin));
                    break;
                case options.u:
                    callback(Module.updatePlugin(plugin));
                    break;
                case options.n:
                    if (args && args.length == 0) {
                        callback(Module.runModule(plugin, module));
                    }
                    else {
                        callback(Module.runModule(plugin, module, args));
                    }
                    break;
            }
        }
    ], function (ris) {
        console.log(ris);
    });
}
else {
    console.error('You must use -m and/or -p option only with -n (--run)!');
}
//# sourceMappingURL=plugin_manager.js.map<commit_msg>Added the module of the plugin manager. Added the module with the four main functions (download, update, remove, run).<commit_after>/**
 * Module which exports four function for download, update, remove and run a plugin in an asynchronous way.
 * Created by matteo on 22/02/16.
 */
/// <reference path="../Module/dl_plugin.ts" />
/// <reference path="../Module/rm_plugin.ts" />
/// <reference path="../Module/up_plugin.ts" />
/// <reference path="../Module/run_plugin.ts" />

/**
 * Function which call a function in an asynchronous way.
 * @param toCall The function which will be called.
 * @param args An array which contains the arguments for the function.
 */
function asyncCall(toCall, args) {
    var async = require('async');
    async.series([
        function (callback) {
            if (args) {
                switch (args.length) {
                    case 1:
                        callback(toCall(args[0]));
                        break;
                    case 2:
                        callback(toCall(args[0], args[1]));
                        break;
                    case 3:
                        callback(toCall(args[0], args[1], args[2]));
                        break;
                }
            } else {
                callback('Can\'t perform the operation: not enough arguments.');
            }
        }
        ],
        function (ris) {
            return ris;
        }
    );
}

var arguments = new Array();

/**
 * Downloads a plugin.
 * @param plugin The url of the plugin.
 */
exports.download = function (plugin) {
    arguments.push(plugin);
    return asyncCall(Module.downloadPlugin, arguments);
}

/**
 * Updates a plugin.
 * @param plugin The url of the plugin.
 */
exports.update = function (plugin) {
    arguments.push(plugin);
    return asyncCall(Module.updatePlugin, arguments);
}

/**
 * Removes a plugin
 * @param plugin The url of the plugin.
 */
exports.remove = function (plugin) {
    arguments.push(plugin);
    return asyncCall(Module.removePlugin, arguments);
}

/**
 * Runs a plugin
 * @param plugin The url of the plugin.
 * @param module The module in the plugin which will be executed.
 * @param args An array which contains the arguments for the execution of the plugin.
 */
exports.run = function (plugin, module, args) {
    arguments.push(plugin); arguments.push(module); arguments.push(args);
    return asyncCall(Module.runModule, arguments);
}
{'fraction_non_alphanumeric': 0.11785260482846252, 'fraction_numerical': 0.00349428208386277, 'mean_word_length': 1.8237668161434977, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3086692', 'n_tokens_mistral': 1705, 'n_tokens_neox': 1634, 'n_words': 583}