Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 23adde539c
Fetching contributors…

Cannot retrieve contributors at this time

58 lines (47 sloc) 1.515 kb
(ns ciste.commands
(:use [ciste.filters :only [deffilter]]
[ciste.routes :only [resolve-routes]]
[ciste.views :only [defview]])
(:require [ciste.predicates :as pred]
[clojure.string :as string]
[ :as log]))
^{:dynamic true
:doc "The sequence of commands that have been registered."}
(ref {}))
^{:dynamic true
:doc "The sequence of predicates used for command dispatch.
By default, commands are dispatched by name."}
(ref [#'pred/name-matches?]))
(defn add-command!
"Adds the fn identified by var v as the command handler for the given name."
[name v]
(alter *commands* assoc name v)))
;; TODO: This should take only a single command map
(defn parse-command
"Takes a sequence of key/value pairs and runs a command"
[{:as command}]
(log/info "parsing command")
(let [{:keys [name args]} command]
((->> @*commands*
(map (fn [[k v]] [{:name k} {:action v}]))
(resolve-routes @*command-predicates*))
(merge command
{:format :text
:serialization :command}))))
;; Should this return a set?
(defn command-names
"The names of all the registered commands."
(sort (keys @*commands*)))
(add-command! "commands-list" #'command-names)
(deffilter #'command-names :command
[action request]
(defview #'command-names :text
[request names]
(string/join "\n" names))
Jump to Line
Something went wrong with that request. Please try again.