Permalink
Browse files

Add interactive task. No more waiting around for JVM boot if that's y…

…our thing.
  • Loading branch information...
1 parent c82fcaf commit 778a522915abe95655d6b99d3603c41958ae9271 @technomancy committed Jul 31, 2010
Showing with 38 additions and 11 deletions.
  1. +14 −11 src/leiningen/core.clj
  2. +24 −0 src/leiningen/interactive.clj
@@ -58,23 +58,26 @@
([] (read-project "project.clj")))
(def aliases (atom {"--help" "help" "-h" "help" "-?" "help" "-v" "version"
- "--version" "version" "überjar" "uberjar"}))
+ "--version" "version" "überjar" "uberjar"
+ "int" "interactive"}))
(def no-project-needed (atom #{"new" "help" "version"}))
(defn task-not-found [& _]
(abort "That's not a task. Use \"lein help\" to list all tasks."))
-(defn resolve-task [task]
- (let [task-ns (symbol (str "leiningen." task))
- task (symbol task)]
- (try
- (when-not (find-ns task-ns)
- (require task-ns))
- (or (ns-resolve task-ns task)
- #'task-not-found)
- (catch java.io.FileNotFoundException e
- #'task-not-found))))
+(defn resolve-task
+ ([task not-found]
+ (let [task-ns (symbol (str "leiningen." task))
+ task (symbol task)]
+ (try
+ (when-not (find-ns task-ns)
+ (require task-ns))
+ (or (ns-resolve task-ns task)
+ not-found)
+ (catch java.io.FileNotFoundException e
+ not-found))))
+ ([task] (resolve-task task #'task-not-found)))
(defn- hook-namespaces [project]
(sort (or (:hooks project)
@@ -0,0 +1,24 @@
+(ns leiningen.interactive
+ (:require [clojure.string :as string])
+ (:use [leiningen.core :only [resolve-task no-project-needed]]))
+
+(defn not-found [& _]
+ (println "That's not a task. Use \"lein help\" to list all tasks."))
@ordnungswidrig
ordnungswidrig Aug 3, 2010

Is it really "lein help"? On #11 it says jus "type help".

@technomancy
technomancy Aug 5, 2010 Owner

Good catch; you're right. Thanks.

+
+(defn interactive
+ "Enter an interactive shell for calling tasks without relaunching new JVMs."
+ [project]
+ (println "Welcome to Leiningen. Type \"help\" for a list of commands.")
+ (loop []
+ (flush)
+ (print "lein> ")
+ (flush)
+ ;; TODO: integrate with tab-completion in jLine
+ (let [input (.readLine *in*)]
+ (when input
+ (let [[task-name & args] (string/split input #"\s")
+ task (resolve-task task-name not-found)]
+ (if (@no-project-needed task-name)
+ (apply task args)
+ (apply task project args))
+ (recur))))))

0 comments on commit 778a522

Please sign in to comment.