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:
parent
3a0a1911f7
commit
c9c5cca4dc
1 changed files with 14 additions and 0 deletions
|
@ -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")))
|
||||
|
||||
|
|
Loading…
Reference in a new issue