 
 (def admin {
   :username "admin" :password "foo"
-  :envs [:dev :qa :prod] 
-  :roles #{:celestial.roles/admin} 
+  :envs [:dev :qa :prod]
+  :roles #{:celestial.roles/admin}
   :operations [] })
 
 (defmacro with-admin [& body]
   `(with-redefs [celestial.security/current-user (fn [] {:username "admin"})
                 celestial.persistency.users/get-user! (fn [a#] admin)]
-       ~@body 
+       ~@body
        ))
 
-(defprotocol Repl 
-  "Basic shell like functions on Celestial model types" 
+(defprotocol Repl
+  "Basic shell like functions on Celestial model types"
   (ls [this] [this & opts])
   (find [this exp])
   (rm [this items])

(def types (Types.))

;; (pretty (ls types))
;; (macroexpand-1 '(|> (ls systems) (grep :os :ubuntu-14.04 :four)))
;; (pretty (|> (ls systems) (grep :os :ubuntu-14.04 )))

  (find [this exp])
  (rm [this systems]
    (doseq [id (map first systems)]
      (s/delete-system! (Integer/valueOf id)))
     [this {:systems []}]
    )
  (grep [this systems k v]
      [this {:systems (filter (partial grep-system k v) (systems :systems))}]))


(defrecord Types [] Repl
  (ls [this]
    [this {:types (map t/get-type (t/all-types))}])
  (ls [this & opts])
  (find [this exp])
  (rm [this types ])
  (grep [this types k v])
  )


(defmulti pretty
  (fn [[_ m]] (clojure.set/intersection (into #{} (keys m)) #{:systems :types})))

(defn render [[id m]]
 (-> m
   (select-keys* [:owner] [:machine :hostname] [:machine :os] [:machine :ip])
   (assoc :id id)))

