From 54c8de178d1bbb2b1d45cc7538503c0963e0aff7 Mon Sep 17 00:00:00 2001 From: Dan Larkin Date: Sat, 12 Dec 2009 16:51:37 -0500 Subject: [PATCH 1/2] use exit-with-error instead of printing an error message and calling System/exit separately every time --- src/leiningen/core.clj | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/leiningen/core.clj b/src/leiningen/core.clj index 8444b8d4..7a5da209 100644 --- a/src/leiningen/core.clj +++ b/src/leiningen/core.clj @@ -34,6 +34,10 @@ ;; So it doesn't need to be fully-qualified in project.clj (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 (defn read-project ([file] (load-file file) @@ -45,20 +49,19 @@ (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] (let [task-ns (symbol (str "leiningen." 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 (require task-ns) (or (ns-resolve task-ns task) - not-found-fn) + error-fn) (catch java.io.FileNotFoundException e - not-found-fn)))) + error-fn)))) (defn -main [& [task & args]] (let [task (or (aliases task) task "help") @@ -71,7 +74,7 @@ (try (apply (resolve-task task) args) (catch IllegalArgumentException _ - (println (format "Wrong number of arguments to task %s." task)) - (System/exit 1)))) + (exit-with-error (format "Wrong number of arguments to task %s." + task))))) ;; In case tests or some other task started any: (shutdown-agents))) From e4e01fe1d10d6f3a79943a9a4582c219ff0149e2 Mon Sep 17 00:00:00 2001 From: Dan Larkin Date: Sat, 12 Dec 2009 16:52:37 -0500 Subject: [PATCH 2/2] print an error message instead of a stack trace when no project.clj is found --- src/leiningen/core.clj | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/leiningen/core.clj b/src/leiningen/core.clj index 7a5da209..0f854240 100644 --- a/src/leiningen/core.clj +++ b/src/leiningen/core.clj @@ -40,8 +40,12 @@ ;; TODO: prompt to run "new" if no project file is found (defn read-project - ([file] (load-file file) - project) + ([file] + (try + (load-file file) + project + (catch java.io.FileNotFoundException _ + (exit-with-error "No project.clj found in this directory.")))) ([] (read-project "project.clj"))) (def aliases {"--help" "help" "-h" "help" "-?" "help"