Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move task chaining to do task. Fixes #632.

  • Loading branch information...
commit 1be0c5edb927cfe601cf9ab14c63aab00557c4db 1 parent a61f188
@technomancy authored
View
49 leiningen-core/src/leiningen/core/main.clj
@@ -15,6 +15,11 @@
"tutorial" ["help" "tutorial"]
"sample" ["help" "sample"]}))
+(defn lookup-alias [task-name project]
+ (or (@aliases task-name)
+ (get (:aliases project) task-name)
+ task-name "help"))
+
(def ^:dynamic *debug* (System/getenv "DEBUG"))
(defn debug [& args]
@@ -114,24 +119,19 @@ or by executing \"lein upgrade\". ")
(info (format min-version-warning
min-lein-version (leiningen-version)))))
-(defn- conj-to-last [coll x]
- (update-in coll [(dec (count coll))] conj x))
-
-(defn ^:internal group-args
- ([args] (reduce group-args [[]] args))
- ([groups arg]
- (if (.endsWith arg ",")
- (-> groups
- (conj-to-last (subs arg 0 (dec (count arg))))
- (conj []))
- (conj-to-last groups arg))))
+(defn- warn-chaining [task-name args]
+ (when (and (some #(.endsWith % ",") (cons task-name args))
+ (not-any? #(= % "do") (cons task-name args)))
+ (println "WARNING: task chaining has been moved to the \"do\" task.")
+ (println "See `lein help do` for details.")))
(defn -main
"Run a task or comma-separated list of tasks."
- [& args]
+ [& [task-name & args]]
(user/init)
(let [project (if (.exists (io/file "project.clj"))
- (project/init-project (project/read)))]
+ (project/init-project (project/read)))
+ task-name (lookup-alias task-name project)]
(when (:min-lein-version project)
(verify-min-version project))
(when-let [{:keys [host port]} (classpath/get-proxy-settings)]
@@ -141,17 +141,14 @@ or by executing \"lein upgrade\". ")
(let [default-project (project/merge-profiles project/defaults [:user :default])]
(project/load-certificates default-project)
(project/load-plugins default-project)))
- (doseq [[task-name & args] (group-args args)
- :let [task-name (or (@aliases task-name)
- (get (:aliases project) task-name)
- task-name "help")]]
- (try (apply-task task-name project args)
- (catch Exception e
- (when-let [[_ code] (and (.getMessage e)
- (re-find #"Process exited with (\d+)"
- (.getMessage e)))]
- (exit (Integer. code)))
- (when-not (re-find #"Suppressed exit:" (or (.getMessage e) ""))
- (.printStackTrace e))
- (exit 1)))))
+ (try (warn-chaining task-name args)
+ (apply-task task-name project args)
+ (catch Exception e
+ (when-let [[_ code] (and (.getMessage e)
+ (re-find #"Process exited with (\d+)"
+ (.getMessage e)))]
+ (exit (Integer. code)))
+ (when-not (re-find #"Suppressed exit:" (or (.getMessage e) ""))
+ (.printStackTrace e))
+ (exit 1))))
(exit 0))
View
20 leiningen-core/test/leiningen/core/test/main.clj
@@ -2,26 +2,6 @@
(:use [clojure.test]
[leiningen.core.main]))
-(deftest test-group-args-empty-args
- (is (= [[]] (group-args []))))
-
-(deftest test-group-args-single-task
- (is (= [["pom"]] (group-args ["pom"]))))
-
-(deftest test-group-args-without-args
- (is (= [["clean"] ["deps"] ["test"]]
- (group-args ["clean," "deps," "test"]))))
-
-(deftest test-group-args-with-args
- (is (= [["test" "test-core"] ["version"]]
- (group-args ["test" "test-core," "version"]))))
-
-(deftest test-group-args-with-long-chain
- (is (= [["help" "help"] ["help" "version"] ["version"]
- ["test" "test-compile"]]
- (group-args '("help" "help," "help" "version," "version,"
- "test" "test-compile")))))
-
(deftest test-matching-arity
(is (not (matching-arity? (resolve-task "bluuugh") ["bogus" "arg" "s"])))
(is (matching-arity? (resolve-task "bluuugh") []))
View
21 src/leiningen/do.clj
@@ -0,0 +1,21 @@
+(ns leiningen.do
+ (:refer-clojure :exclude [do])
+ (:require [leiningen.core.main :as main]))
+
+(defn- conj-to-last [coll x]
+ (update-in coll [(dec (count coll))] conj x))
+
+(defn ^:internal group-args
+ ([args] (reduce group-args [[]] args))
+ ([groups arg]
+ (if (.endsWith arg ",")
+ (-> groups
+ (conj-to-last (subs arg 0 (dec (count arg))))
+ (conj []))
+ (conj-to-last groups arg))))
+
+(defn ^:no-project-needed do
+ "Perform comma-separated tasks in succession."
+ [project & args]
+ (doseq [[task-name & args] (group-args args)]
+ (main/apply-task (main/lookup-alias task-name project) project args)))
View
24 test/leiningen/test/do.clj
@@ -0,0 +1,24 @@
+(ns leiningen.test.do
+ (:refer-clojure :exclude [do])
+ (:use [clojure.test]
+ [leiningen.do]))
+
+(deftest test-group-args-empty-args
+ (is (= [[]] (group-args []))))
+
+(deftest test-group-args-single-task
+ (is (= [["pom"]] (group-args ["pom"]))))
+
+(deftest test-group-args-without-args
+ (is (= [["clean"] ["deps"] ["test"]]
+ (group-args ["clean," "deps," "test"]))))
+
+(deftest test-group-args-with-args
+ (is (= [["test" "test-core"] ["version"]]
+ (group-args ["test" "test-core," "version"]))))
+
+(deftest test-group-args-with-long-chain
+ (is (= [["help" "help"] ["help" "version"] ["version"]
+ ["test" "test-compile"]]
+ (group-args '("help" "help," "help" "version," "version,"
+ "test" "test-compile")))))
View
2  todo.org
@@ -4,12 +4,12 @@ See also https://github.com/technomancy/leiningen/issues
* For 2.0.0
** 2.0.0-final
+ - [X] Address chaining issues in with-profile (#632)
- [ ] Address gpg agent issues (#615)
- [ ] Startup performance regression (#614)
- [ ] Stale directory clutter (#589)
- [ ] Allow jars to be signed, document in deploying guide. (#519)
- [ ] Isolate target dir per profile (#468)
- - [ ] Address chaining issues in with-profile (#632)
- [ ] Mirror support (#271)
- [ ] Honor mirror for search indices (#281)
- [ ] Reduce Aether verbosity (#610)
Please sign in to comment.
Something went wrong with that request. Please try again.