var Q = require("q");
var _ = require("hr.utils");
var Collection = require("hr.collection");
var logger = require("hr.logger")("commands");

var Command = require("../models/command");

var Commands = Collection.extend({
    model: Command,

    // Initialize
    initialize: function() {
        Commands.__super__.initialize.apply(this, arguments);

        this.context = {};
    },

    // Register a new command
    register: function(cmd) {
        if (_.isArray(cmd)) return _.map(cmd, this.register, this);

        var c = this.get(cmd.id);
        if (c) this.remove(c);

        return this.add(cmd);
    },

    // Run a command
    run: function(cmd, args) {

        cmd = this.get(cmd);
        if (!cmd) return Q.reject(new Error("Command not found: '"+cmd+"'"));

        return cmd.run(args);
    },

    // Set context
    setContext: function(id, data) {
        logging.log("update context", id);
        this.context = {
            'type': id,
            'data': data
        };
        this.trigger("context", this.context);
    }
});

module.exports = Commands;

@@ -653,16 +653,17 @@
 unction(
+_
 cmd, arg
@@ -667,25 +667,24 @@
 args) %7B%0A
-%0A
         
 cmd = th
@@ -675,16 +675,20 @@
         
+var 
 cmd = th
@@ -694,16 +694,17 @@
 his.get(
+_
 cmd);%0A  
@@ -768,16 +768,17 @@
 und: '%22+
+_
 cmd+%22'%22)

Fix error message when command not found