-
-
Save sritchie/8e425184bd226f510425 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def loc | |
"The location of lein's custom environment file." | |
".lein-env") | |
(defn with-env* | |
"Executes the supplied function in an environment where conf's kv | |
pairs override the default config." | |
[conf f] | |
{:pre [(map? conf)]} | |
(let [old-env (try (slurp loc) | |
(catch java.io.FileNotFoundException _))] | |
(spit loc (prn-str conf)) | |
(require '[environ.core :reload true]) | |
(try (f) | |
(finally | |
(when old-env (spit loc old-env)) | |
(require '[environ.core :reload true]))))) | |
(defmacro with-env | |
"Executes the supplied body in an environment where conf's bindings | |
override the default env." | |
[conf & body] | |
`(with-env* ~conf (fn [] ~@body))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment