Merge commit 'danlarkin/catch-missing-project'
This commit is contained in:
commit
83ab2890b0
1 changed files with 18 additions and 11 deletions
|
@ -34,10 +34,18 @@
|
||||||
;; So it doesn't need to be fully-qualified in project.clj
|
;; So it doesn't need to be fully-qualified in project.clj
|
||||||
(with-ns 'clojure.core (use ['leiningen.core :only ['defproject]]))
|
(with-ns 'clojure.core (use ['leiningen.core :only ['defproject]]))
|
||||||
|
|
||||||
|
(defn exit-with-error [msg]
|
||||||
|
(println msg)
|
||||||
|
(System/exit 1))
|
||||||
|
|
||||||
;; TODO: prompt to run "new" if no project file is found
|
;; TODO: prompt to run "new" if no project file is found
|
||||||
(defn read-project
|
(defn read-project
|
||||||
([file] (load-file file)
|
([file]
|
||||||
project)
|
(try
|
||||||
|
(load-file file)
|
||||||
|
project
|
||||||
|
(catch java.io.FileNotFoundException _
|
||||||
|
(exit-with-error "No project.clj found in this directory."))))
|
||||||
([] (read-project "project.clj")))
|
([] (read-project "project.clj")))
|
||||||
|
|
||||||
(def aliases {"--help" "help" "-h" "help" "-?" "help"
|
(def aliases {"--help" "help" "-h" "help" "-?" "help"
|
||||||
|
@ -45,20 +53,19 @@
|
||||||
|
|
||||||
(def no-project-needed #{"new" "help" "version"})
|
(def no-project-needed #{"new" "help" "version"})
|
||||||
|
|
||||||
(defn task-not-found [task project & _]
|
|
||||||
(println task "is not a task. Use \"help\" to list all tasks.")
|
|
||||||
(System/exit 1))
|
|
||||||
|
|
||||||
(defn resolve-task [task]
|
(defn resolve-task [task]
|
||||||
(let [task-ns (symbol (str "leiningen." task))
|
(let [task-ns (symbol (str "leiningen." task))
|
||||||
task (symbol task)
|
task (symbol task)
|
||||||
not-found-fn (partial task-not-found task)]
|
error-fn (fn [& _]
|
||||||
|
(exit-with-error
|
||||||
|
(format "%s is not a task. Use \"help\" to list all tasks."
|
||||||
|
task)))]
|
||||||
(try
|
(try
|
||||||
(require task-ns)
|
(require task-ns)
|
||||||
(or (ns-resolve task-ns task)
|
(or (ns-resolve task-ns task)
|
||||||
not-found-fn)
|
error-fn)
|
||||||
(catch java.io.FileNotFoundException e
|
(catch java.io.FileNotFoundException e
|
||||||
not-found-fn))))
|
error-fn))))
|
||||||
|
|
||||||
(defn -main [& [task & args]]
|
(defn -main [& [task & args]]
|
||||||
(let [task (or (aliases task) task "help")
|
(let [task (or (aliases task) task "help")
|
||||||
|
@ -71,7 +78,7 @@
|
||||||
(try
|
(try
|
||||||
(apply (resolve-task task) args)
|
(apply (resolve-task task) args)
|
||||||
(catch IllegalArgumentException _
|
(catch IllegalArgumentException _
|
||||||
(println (format "Wrong number of arguments to task %s." task))
|
(exit-with-error (format "Wrong number of arguments to task %s."
|
||||||
(System/exit 1))))
|
task)))))
|
||||||
;; In case tests or some other task started any:
|
;; In case tests or some other task started any:
|
||||||
(shutdown-agents)))
|
(shutdown-agents)))
|
||||||
|
|
Loading…
Reference in a new issue