Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{:paths ["environ/src"]}
23 changes: 18 additions & 5 deletions environ/src/environ/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@
(str/replace "." "-")
(keyword)))

(defn- -println [& args]
#_(:clj (.println System/err (apply str args))
:cljs (.error js/console (apply str args))))

(defn- sanitize-key [k]
(let [s (keywordize (name k))]
(if-not (= k s) (println "Warning: environ key" k "has been corrected to" s))
(if-not (= k s) (-println "Warning: environ key" k "has been corrected to" s))
s))

(defn- sanitize-val [k v]
(if (string? v)
v
(do (println "Warning: environ value" (pr-str v) "for key" k "has been cast to string")
(do (-println "Warning: environ value" (pr-str v) "for key" k "has been cast to string")
(str v))))

(defn- read-system-env []
Expand Down Expand Up @@ -58,8 +62,8 @@
(doseq [[k kvs] (group-by key (apply concat ms))
:let [vs (map val kvs)]
:when (and (next kvs) (not= (first vs) (last vs)))]
(println "Warning: environ value" (first vs) "for key" k
"has been overwritten with" (last vs))))
(-println "Warning: environ value" (first vs) "for key" k
"has been overwritten with" (last vs))))

(defn- merge-env [& ms]
(warn-on-overwrite ms)
Expand All @@ -77,5 +81,14 @@
(read-system-env))
{})))

(defonce ^{:doc "A map of environment variables."}
(defonce ^{:doc "A map of environment variables."
:dynamic true}
env (read-env))

#?(:clj
(defn read-runtime-env
"Native image compilation won't work for environ.core/env
as it is compiled with current environment and not runtime environment
variables."
[]
(alter-var-root #'env (fn [_] (read-env)))))