weavejester / environ

Library for managing environment variables in Clojure
924 stars 71 forks source link

Reverse the construction of environ.core/env to resolve variable in the correct order #79

Closed fmind closed 6 years ago

fmind commented 6 years ago

The README suggests that environment variables should be resolved in the following order:

However, the current implementation does not reflect the order described (see below):

(defonce ^{:doc "A map of environment variables."}
  env
  (merge
   (read-env-file ".lein-env")
   (read-env-file (io/resource ".boot-env"))
   (read-system-env)
   (read-system-props)))

clojure.core/merge overrides values from right to left (arg 1 < arg 2 < arg 3 ...):

(merge {:a 1 :b 2 :c 3} {:a 9 :b 8 :d 7})
=> {:a 9, :b 8, :c 3, :d 7}

My PR rewrites the order as follow to reflect the property of clojure.core/merge

(defonce ^{:doc "A map of environment variables."}
  env
  (merge
   (read-system-props)
   (read-system-env)
   (read-env-file (io/resource ".boot-env"))
   (read-env-file ".lein-env")))
weavejester commented 6 years ago

Thanks for the patch, but the README should be made clearer, rather than the functionality of the library changed.