Skip to content

Commit

Permalink
Merge pull request technomancy#1769 from RyanMcG/fix-pass-through-hel…
Browse files Browse the repository at this point in the history
…p-on-vector-aliases

Fix pass-through-help on vector aliases by merging meta on aliases
  • Loading branch information
technomancy committed Dec 5, 2014
2 parents 1296288 + 02c9f31 commit b4ed256
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
17 changes: 12 additions & 5 deletions leiningen-core/src/leiningen/core/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,25 @@
(swap! atom dissoc key)
v))

(defn- merge-alias-meta [task-vector task-name]
(merge (select-keys (meta task-vector) [:doc :pass-through-help])
(meta task-name)))

(defn lookup-alias
"Recursively look up aliases until the task is not an alias anymore. If
task-name is a vector, calls lookup-alias on the first argument and returns a
partially applied task. Discards already used aliases."
[task-name project & [not-found]]
(if (vector? task-name)
(let [[t & args] task-name ;; never mind the poor naming here.
resolved-task (lookup-alias t project not-found)]
(into (if (vector? resolved-task)
resolved-task
[resolved-task])
args))
resolved-task (lookup-alias t project not-found)
task-vector (if (vector? resolved-task)
resolved-task
[resolved-task])
merged-meta (merge-alias-meta task-vector task-name)]
(-> task-vector
(into args)
(with-meta merged-meta)))
(let [project-wo-alias (update-in project [:aliases] dissoc task-name)
resolved-task (or (aliases task-name)
(get (:aliases project) task-name)
Expand Down
20 changes: 19 additions & 1 deletion leiningen-core/test/leiningen/core/test/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,28 @@
(is (= "Warning message\n" (with-err-str
(warn "Warning message"))))))

(deftest test-lookup-alias
(testing "meta merging"
(let [project {:aliases {"a" ^:foo ["root"]
"b" ^:bar ["a"]
"c" ^{:pass-through-help false :doc "Yo"} ["b"]
"d" ^:pass-through-help ["c"]}}]
(are [task m] (= (meta (lookup-alias task project)) m)
"a" {:foo true}
"b" {:bar true}
"c" {:doc "Yo" :pass-through-help false}
"d" {:pass-through-help true :doc "Yo"}))))

(deftest test-task-args-help-pass-through
(let [project {:aliases {"sirius-p" ["sirius" "partial"]
"s" "sirius"
"s-p" ["s" "partial"]
"sirius-pp" ["sirius-p" "foo"]
"sp" "s-p"
"test" "test"
"ohai" ^:pass-through-help ["run" "-m" "o.hai"]}}]
"ohai" ^:pass-through-help ["run" "-m" "o.hai"]
"aliaso" ["ohai"]
"aliaso2" ["ohai"]}}]
(testing "with :pass-through-help meta"
(testing "on a var"
(are [res arg] (= res (task-args arg project))
Expand All @@ -49,6 +63,10 @@
[["sirius" "partial" "foo"] ["bar"]] ["sirius-pp" "bar"]
["test" []] ["test"]
["sirius" []] ["s"]
[["run" "-m" "o.hai"] ["-h"]] ["ohai" "-h"]
[["run" "-m" "o.hai"] ["-h"]] ["aliaso" "-h"]
[["run" "-m" "o.hai"] ["-h"]] ["aliaso2" "-h"]
[["run" "-m" "o.hai"] ["--help"]] ["ohai" "--help"]
[["run" "-m" "o.hai"] ["help"]] ["ohai" "help"])))))

(deftest test-matching-arity
Expand Down

0 comments on commit b4ed256

Please sign in to comment.