
var CLIENT_COMMANDS = (function() {
    /** @type {Array<{name:string!, names: Array<string>!, desc: string!, usage: string!, category: string!, exec: Function!}>} */
    var commands = [];

    return {
        getCommand: function(name) {
            for (var i =0, nbCmd = commands.length; i < nbCmd; i++)
                if (commands[i].names.indexOf(name) !== -1)
                    return commands[i];
            return null;
        },
        getCommandsStartingWith: function(cmdPrefix) {
            var result = [];
            commands.forEach(function(cmd) {
                for (var i =0, nbNames =cmd.names.length; i < nbNames; i++)
                    if (cmd.names[i].substr(0, cmdPrefix.length) === cmdPrefix) {
                        result.push(cmd);
                        break;
                    }
            });
            return result;
        },
        /** @type {function({name: string!, names: Array<string>!, desc: string!, usage: string!})} */
        registerCommand: function(cmdObj) {
            cmdObj.category = "client";
            cmdObj.exec = cmdObj.exec.bind(cmdObj);
            commands.push(/** @type {{name: string!, names: Array<string>!, desc: string!, usage: string!, category: string!, exec: Function!}} */ (cmdObj));
        }
    };
})();

