Skip to content

Instantly share code, notes, and snippets.

@sritchie
Created October 29, 2013 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sritchie/8e425184bd226f510425 to your computer and use it in GitHub Desktop.
Save sritchie/8e425184bd226f510425 to your computer and use it in GitHub Desktop.
(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