Commits

Meikel Brandmeyer committed ede9885

Add middleware option

Comments (0)

Files changed (2)

clojuresque-nrepl-runtime/src/main/resources/clojuresque/tasks/repl.clj

 
 (util/deftask start-repl
   [{:keys [port handler middleware]}]
-  (let [p (if (string? port)
-            (Long/parseLong port)
-            port)
-        h (if handler
-            (let [custom-handler (util/resolve-required handler)]
-              (when-not custom-handler
-                (throw (Exception. (str "Unknown handler: " handler))))
-              (custom-handler))
-            (repl/default-handler))
-        s (repl/start-server :port p :handler h)]
+  (let [p   (if (string? port)
+              (Long/parseLong port)
+              port)
+        mw  (map util/resolve-required middleware)
+        h   (if handler
+              (let [custom-handler (util/resolve-required handler)]
+                (when-not custom-handler
+                  (throw (Exception. (str "Unknown handler: " handler))))
+                (custom-handler))
+              (apply repl/default-handler mw))
+        s   (repl/start-server :port p :handler h)]
     (println "Repl started on port" port)
     (alter-var-root #'server (constantly s)))
   @barrier)

clojuresque-nrepl/src/main/groovy/clojuresque/tasks/ClojureRepl.groovy

  *   (repl/default-handler #'my-middleware))
  * </code></pre>
  *
+ * If all you want is to specify custom middleware, there is a
+ * short-hand in the <code>middleware</code> option. Here you can
+ * specify the fully-qualified names of the middleware in the desired
+ * order.
+ *
+ * <pre><code>clojureRepl {
+ *     middleware &lt;&lt; "my.repl/middleware"
+ * }
+ * </code></pre>
+ *
  * <em>Note:</em> You have to specify the nrepl version to use
  * manually. Eg. by using the “development” configuration or
  * as part of your application.
 
     def port
     def handler
+    def middleware = []
 
     @TaskAction
     void startRepl() {
         def options = [
             port:    port,
-            handler: handler
+            handler: handler,
+            middleware: middleware
         ]
 
         project.clojureexec {