Make profile aliases available outside projects.

Fixes #978.

By adding an atom (to pop off used aliases to avoid recursive calls)
which contains :user :aliases from profiles, we can use those aliases
outside of project maps. Whenever looking up aliases, will check the
atom if we're not in a project.
This commit is contained in:
Jean Niklas L'orange 2013-02-03 13:20:03 +01:00
parent 3a0a1911f7
commit c9c5cca4dc

View file

@ -19,9 +19,23 @@
"tutorial" ["help" "tutorial"]
"sample" ["help" "sample"]})
(def ^:private profile-aliases
"User profile aliases, used only when Lein is not within a project."
(atom (-> (user/profiles) :user :aliases)))
(defn- get-and-dissoc!
"Returns a value associated with a key in a hash map contained in an atom,
removing it if it exists."
[atom key]
(when-let [[k v] (find @atom key)]
(swap! atom dissoc key)
v))
(defn lookup-alias [task-name project & [not-found]]
(or (aliases task-name)
(get (:aliases project) task-name)
(when-not project
(get-and-dissoc! profile-aliases task-name))
task-name
(or not-found "help")))