Skip to content

Commit

Permalink
Add interactive task. No more waiting around for JVM boot if that's y…
Browse files Browse the repository at this point in the history
…our thing.
  • Loading branch information
technomancy committed Jul 31, 2010
1 parent c82fcaf commit 778a522
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/leiningen/core.clj
Expand Up @@ -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)
Expand Down
24 changes: 24 additions & 0 deletions src/leiningen/interactive.clj
@@ -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."))

This comment has been minimized.

Copy link
@ordnungswidrig

ordnungswidrig Aug 3, 2010

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

This comment has been minimized.

Copy link
@technomancy

technomancy Aug 5, 2010

Author 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.