unifying interactive and normal task calling

This commit is contained in:
Colin Jones 2010-07-31 15:58:58 -05:00
parent af71f1d529
commit 7acdf16a29
2 changed files with 14 additions and 14 deletions

View file

@ -102,8 +102,16 @@
(replace \_ \-)
(replace \/ \.)))
(defn project-needed [taskname]
(some #{'project} (map first (:arglists (meta (resolve-task taskname))))))
(defn project-needed [task-name]
(some #{'project} (map first (:arglists (meta (resolve-task task-name))))))
(defn apply-task [task-name project args not-found]
;; TODO: can we catch only task-level arity problems here?
;; compare args and (:arglists (meta (resolve-task task)))?
(let [task (resolve-task task-name not-found)]
(if (project-needed task-name)
(apply task project args)
(apply task args))))
(defn -main
([& [task-name & args]]
@ -114,12 +122,7 @@
(binding [*compile-path* compile-path]
(when project
(load-hooks project))
;; TODO: can we catch only task-level arity problems here?
;; compare args and (:arglists (meta (resolve-task task)))?
(let [task (resolve-task task-name)
value (apply task (if project
(cons project args)
args))]
(let [value (apply-task task-name project args task-not-found)]
(when (integer? value)
(System/exit value))))))
([] (apply -main (or *command-line-args* ["help"]))))

View file

@ -1,6 +1,6 @@
(ns leiningen.interactive
(:require [clojure.string :as string])
(:use [leiningen.core :only [resolve-task project-needed]]))
(:use [leiningen.core :only [apply-task]]))
(defn not-found [& _]
(println "That's not a task. Use \"lein help\" to list all tasks."))
@ -16,9 +16,6 @@
;; 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 (project-needed task-name)
(apply task project args)
(apply task args))
(let [[task-name & args] (string/split input #"\s")]
(apply-task task-name project args not-found)
(recur))))))