Add interactive task. No more waiting around for JVM boot if that's your thing.

This commit is contained in:
Phil Hagelberg 2010-07-30 21:17:07 -07:00
parent c82fcaf4c1
commit 778a522915
2 changed files with 38 additions and 11 deletions

View file

@ -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)

View file

@ -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."))
(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))))))