 
 
 (defn handle-commands
+  "This functions starts the command loop. It uses the handle-command
+  multi-method for handling the individual commands (except shutdown).
+  See the documentation on the handle-command for more info on this.
+  This function receives the spec, the root systems and a map of
+  started boxes. More boxes may be started from the command loop, or
+  stopped. Therefore, this function returns an updated map of
+  currently running boxes."
   [spec systems boxes]
   ;; Handle commands like starting and stopping modules, and stopping the application.
   ;; This can be done through typing here, updates on the file system, through sockets...

    (f systems)))



(defn start-box
  [module resolve-dependencies]
  (try
    (let [box (boxure {:resolve-dependencies resolve-dependencies

        boxes))))


(defn stop-boxes
  "Calls the stop function of all boxes in the specefied boxes map."
  [boxes]
  (doseq [[name box] boxes]
    (try
      ;; Box stop logic here.
      (catch Throwable ex
        (println "Exception while stopping module" name ":" ex)
        ;; Kill box here?
        ))))


;;; Command loop.

(defmulti handle-command
  "This multi-method dispatches on the command (the first word in the
  command string). It receives the arguments, the spec, the current
  command-loop state and the running boxes map. This method may return
  a pair, where the first item is an updated state map, and the second
  item is an updated boxes map. If no value is returned, or a value in
  the pair is nil, then the state and/or boxes are not updated in the
  command-loop."
  (fn [command args spec state boxes] command))


