|
@@ -2865,8 +2865,8 @@ net.brehaut.ClojureTools = (function (SH) {
|
2865
|
2865
|
build_tree: build_tree
|
2866
|
2866
|
};
|
2867
|
2867
|
})(SyntaxHighlighter);
|
2868
|
|
-</script><title>coreagile/defenv -- Marginalia</title></head><body><table><tr><td class="docs"><div class="header"><h1 class="project-name"><a href="https://defenv.calmabiding.me/">coreagile/defenv</a></h1><h2 class="project-version">0.5.1</h2><br /><p>A simple library for managing environment variables in Clojure</p>
|
2869
|
|
-</div><div class="dependencies"><h3>dependencies</h3><table><tr><td class="dep-name">org.clojure/clojure</td><td class="dotted"><hr /></td><td class="dep-version">1.8.0</td></tr><tr><td class="dep-name">slingshot</td><td class="dotted"><hr /></td><td class="dep-version">0.12.2</td></tr></table></div></td><td class="codes" style="text-align: center; vertical-align: middle;color: #666;padding-right:20px"><br /><br /><br />(this space intentionally left almost blank)</td></tr><tr><td class="docs"><div class="toc"><a name="toc"><h3>namespaces</h3></a><ul><li><a href="#defenv.core">defenv.core</a></li><li><a href="#defenv.usage">defenv.usage</a></li></ul></div></td><td class="codes"> </td></tr><tr><td class="docs"><div class="docs-header"><a class="anchor" href="#defenv.core" name="defenv.core"><h1 class="project-name">defenv.core</h1><a class="toc-link" href="#toc">toc</a></a></div></td><td class="codes" /></tr><tr><td class="docs"><h1>Welcome to defenv</h1>
|
|
2868
|
+</script><title>coreagile/defenv -- Marginalia</title></head><body><table><tr><td class="docs"><div class="header"><h1 class="project-name"><a href="https://defenv.calmabiding.me/">coreagile/defenv</a></h1><h2 class="project-version">1.0.0</h2><br /><p>A simple library for managing environment variables in Clojure</p>
|
|
2869
|
+</div><div class="dependencies"><h3>dependencies</h3><table><tr><td class="dep-name">org.clojure/clojure</td><td class="dotted"><hr /></td><td class="dep-version">1.8.0</td></tr><tr><td class="dep-name">slingshot</td><td class="dotted"><hr /></td><td class="dep-version">0.12.2</td></tr></table></div></td><td class="codes" style="text-align: center; vertical-align: middle;color: #666;padding-right:20px"><br /><br /><br />(this space intentionally left almost blank)</td></tr><tr><td class="docs"><div class="toc"><a name="toc"><h3>namespaces</h3></a><ul><li><a href="#defenv.core">defenv.core</a></li><li><a href="#defenv.usage">defenv.usage</a></li><li><a href="#defenv.docs">defenv.docs</a></li></ul></div></td><td class="codes"> </td></tr><tr><td class="docs"><div class="docs-header"><a class="anchor" href="#defenv.core" name="defenv.core"><h1 class="project-name">defenv.core</h1><a class="toc-link" href="#toc">toc</a></a></div></td><td class="codes" /></tr><tr><td class="docs"><h1>Welcome to defenv</h1>
|
2870
|
2870
|
|
2871
|
2871
|
<p>This library attempts to simplify the management of environment variables.
|
2872
|
2872
|
Put simply, it's <code>System/getenv</code> on steroids.</p>
|
|
@@ -2973,7 +2973,7 @@ doesn't throw exceptions when loading namespaces (a huge pet peeve!).</p>
|
2973
|
2973
|
base-value (-> tfn str pretty-demunge)
|
2974
|
2974
|
(if masked? "--ERROR MASKED--" (.getMessage e))))
|
2975
|
2975
|
::parse-error)))</pre></td></tr><tr><td class="docs">
|
2976
|
|
-</td><td class="codes"><pre class="brush: clojure">(defn- overlay-env [m k {:keys [optional? masked?] env-name :env :as params}]
|
|
2976
|
+</td><td class="codes"><pre class="brush: clojure">(defn- overlay-env [m k {:keys [optional? masked? env-name] :as params}]
|
2977
|
2977
|
(let [{:keys [tfn params-to-display base-value]} (parse-env env-name params)
|
2978
|
2978
|
v (try-tfn env-name masked? tfn base-value)]
|
2979
|
2979
|
(-> m
|
|
@@ -2990,18 +2990,18 @@ required variable is missing, not just the one you ask for.</p>
|
2990
|
2990
|
|
2991
|
2991
|
<p>The map should look something like this:</p>
|
2992
|
2992
|
|
2993
|
|
-<pre><code>{:ev1 {:env "MY_ENV_VAR"
|
|
2993
|
+<pre><code>{:ev1 {:env-name "MY_ENV_VAR"
|
2994
|
2994
|
:tfn my-optional-parse-function
|
2995
|
2995
|
:default "MY OPTIONAL DEFAULT VALUE"
|
2996
|
2996
|
:masked? true
|
2997
|
2997
|
:doc "Nice documentation"
|
2998
|
2998
|
:optional? true}
|
2999
|
|
- :other {:env "OTHER_VAR"}}
|
|
2999
|
+ :other {:env-name "OTHER_VAR"}}
|
3000
|
3000
|
</code></pre>
|
3001
|
3001
|
|
3002
|
3002
|
<p>In this case, the <code>:ev1</code> key will be filled in with the value of
|
3003
|
3003
|
<code>MY_ENV_VAR</code>, unless it isn't present, in which case, it will receive the
|
3004
|
|
-value <code>MY OPTIONAL DEFAULT VALUE</code>. Every key except for <code>:env</code> is optional.</p>
|
|
3004
|
+value <code>MY OPTIONAL DEFAULT VALUE</code>. Every key except for <code>:env-name</code> is optional.</p>
|
3005
|
3005
|
|
3006
|
3006
|
<p>In the case of <code>:other</code>, if there is no value for <code>OTHER_VAR</code>, there will be
|
3007
|
3007
|
an exception thrown much like when attempting to deref a binding generated
|
|
@@ -3011,10 +3011,10 @@ by <code>defenv</code>that is required but missing.</p>
|
3011
|
3011
|
(let [{:keys [env-map display-spec]} (get-env-info env-spec)]
|
3012
|
3012
|
(throw-usage-if-missing display-spec)
|
3013
|
3013
|
env-map))</pre></td></tr><tr><td class="docs"><p>Get a single environment variable value. You can use any of the params
|
3014
|
|
- that you would use in <code>env->map</code> except <code>:env</code>, which is the <code>env-name</code>.</p>
|
|
3014
|
+ that you would use in <code>env->map</code> except <code>:env-name</code>, which is the <code>env-name</code>.</p>
|
3015
|
3015
|
</td><td class="codes"><pre class="brush: clojure">(defn one
|
3016
|
3016
|
[env-name & params]
|
3017
|
|
- (:e (env->map {:e (into {:env env-name} (apply hash-map params))})))</pre></td></tr><tr><td class="docs"><h3>Defining a global environment variable binding</h3>
|
|
3017
|
+ (:e (env->map {:e (into {:env-name env-name} (apply hash-map params))})))</pre></td></tr><tr><td class="docs"><h3>Defining a global environment variable binding</h3>
|
3018
|
3018
|
</td><td class="codes"></td></tr><tr><td class="docs">
|
3019
|
3019
|
</td><td class="codes"><pre class="brush: clojure">(def ^:private global-defined-spec (ref (sorted-map)))
|
3020
|
3020
|
(def ^:private global-parsed-env (ref (sorted-map)))
|
|
@@ -3078,7 +3078,7 @@ missing.</p>
|
3078
|
3078
|
(when env-or-fk (concat [env-or-fk] remaining)))
|
3079
|
3079
|
(apply hash-map)
|
3080
|
3080
|
(add-doc doc-present? doc-or-env))
|
3081
|
|
- params (assoc params :env env-name)]
|
|
3081
|
+ params (assoc params :env-name env-name)]
|
3082
|
3082
|
`(do (add-to-global-defined-spec! ~env-name ~params)
|
3083
|
3083
|
(def ^:dynamic ~b (delay (get-global-env ~env-name))))))</pre></td></tr><tr><td class="docs"><h2>Displaying environment information to your users</h2>
|
3084
|
3084
|
</td><td class="codes"></td></tr><tr><td class="docs">
|
|
@@ -3091,7 +3091,10 @@ missing.</p>
|
3091
|
3091
|
</td><td class="codes"><pre class="brush: clojure">(defn display-env
|
3092
|
3092
|
([] (guarantee-global! (display-env-internal @global-display-spec)))
|
3093
|
3093
|
([env-spec]
|
3094
|
|
- (display-env-internal (:display-spec (get-env-info env-spec)))))</pre></td></tr><tr><td class="docs"><h2>Test fixtures</h2>
|
|
3094
|
+ (display-env-internal (:display-spec (get-env-info env-spec)))))</pre></td></tr><tr><td class="docs"><p>Extract the global environment config as a list of maps</p>
|
|
3095
|
+</td><td class="codes"><pre class="brush: clojure">(defn extract-global-spec
|
|
3096
|
+ [f]
|
|
3097
|
+ (guarantee-global! (map (comp f second) @global-defined-spec)))</pre></td></tr><tr><td class="docs"><h2>Test fixtures</h2>
|
3095
|
3098
|
</td><td class="codes"></td></tr><tr><td class="docs">
|
3096
|
3099
|
</td><td class="codes"><pre class="brush: clojure">(defn reset-defined-env!
|
3097
|
3100
|
[]
|
|
@@ -3128,13 +3131,14 @@ missing.</p>
|
3128
|
3131
|
</td><td class="codes"><pre class="brush: clojure">(env/defenv parse-error "DEFENV_UNPARSEABLE"
|
3129
|
3132
|
:tfn parse-broken :default "broken")</pre></td></tr><tr><td class="docs"><h3>Local Map</h3>
|
3130
|
3133
|
</td><td class="codes"></td></tr><tr><td class="docs">
|
3131
|
|
-</td><td class="codes"><pre class="brush: clojure">(def env-map-spec {:testing {:env "DEFENV_TESTING" :default sensible-default}
|
3132
|
|
- :log-level {:env "LOG_LEVEL" :doc "Global log level."
|
|
3134
|
+</td><td class="codes"><pre class="brush: clojure">(def env-map-spec {:testing {:env-name "DEFENV_TESTING"
|
|
3135
|
+ :default sensible-default}
|
|
3136
|
+ :log-level {:env-name "LOG_LEVEL" :doc "Global log level."
|
3133
|
3137
|
:tfn keyword :default "info"}
|
3134
|
|
- :should-log? {:env "SHOULD_LOG"
|
|
3138
|
+ :should-log? {:env-name "SHOULD_LOG"
|
3135
|
3139
|
:doc "Should I log? A boolean."
|
3136
|
3140
|
:tfn env/parse-bool :default "false"}
|
3137
|
|
- :optional {:env "DEFENV_OPT" :optional? true
|
|
3141
|
+ :optional {:env-name "DEFENV_OPT" :optional? true
|
3138
|
3142
|
:doc "A truly optional value."}})
|
3139
|
3143
|
(def env-map (env/env->map env-map-spec))</pre></td></tr><tr><td class="docs">
|
3140
|
3144
|
</td><td class="codes"><pre class="brush: clojure">(defmacro handle-exception [& body]
|
|
@@ -3157,7 +3161,45 @@ missing.</p>
|
3157
|
3161
|
(env/set-error-print-enabled! true)
|
3158
|
3162
|
(env/set-err-print-fn! #(log/error %))
|
3159
|
3163
|
(printf "Exception Printing: %s%n" @testing)
|
3160
|
|
- (handle-exception @missing))</pre></td></tr><tr><td class="spacer docs"> </td><td class="codes" /></tr></table><div class="footer">Generated by <a href="https://github.com/gdeer81/marginalia">Marginalia</a>. Syntax highlighting provided by Alex Gorbatchev's <a href="http://alexgorbatchev.com/SyntaxHighlighter/">SyntaxHighlighter</a><div id="floating-toc"><ul><li class="floating-toc-li" id="floating-toc_defenv.core">defenv.core</li><li class="floating-toc-li" id="floating-toc_defenv.usage">defenv.usage</li></ul></div></div><script type="text/javascript">SyntaxHighlighter.defaults['gutter'] = false;
|
|
3164
|
+ (handle-exception @missing))</pre></td></tr><tr><td class="spacer docs"> </td><td class="codes" /></tr><tr><td class="docs"><div class="docs-header"><a class="anchor" href="#defenv.docs" name="defenv.docs"><h1 class="project-name">defenv.docs</h1><a class="toc-link" href="#toc">toc</a></a></div></td><td class="codes" /></tr><tr><td class="docs">
|
|
3165
|
+</td><td class="codes"><pre class="brush: clojure">(ns defenv.docs
|
|
3166
|
+ (:require [defenv.core :as env]
|
|
3167
|
+ [hiccup.core :as h]))</pre></td></tr><tr><td class="docs"><h1>Documentation Generation</h1>
|
|
3168
|
+</td><td class="codes"></td></tr><tr><td class="docs">
|
|
3169
|
+</td><td class="codes"><pre class="brush: clojure">(defn- env-var->html [{:keys [env-name default optional? masked? doc]}]
|
|
3170
|
+ [[:dd env-name]
|
|
3171
|
+ [:dt
|
|
3172
|
+ (when (or default optional? masked?)
|
|
3173
|
+ [:ul
|
|
3174
|
+ (when default
|
|
3175
|
+ [:li {:class "default-value"} "Default: "
|
|
3176
|
+ [:span default]])
|
|
3177
|
+ (when optional? [:li {:class "optional"} "optional"])
|
|
3178
|
+ (when masked? [:li {:class "masked"} "masked"])])
|
|
3179
|
+ [:span {:class "doc"} (or doc [:i "No documentation found"])]]])</pre></td></tr><tr><td class="docs">
|
|
3180
|
+</td><td class="codes"><pre class="brush: clojure">(defn- env->html [header]
|
|
3181
|
+ (h/html
|
|
3182
|
+ [:html
|
|
3183
|
+ [:head
|
|
3184
|
+ [:link {:type "text/css" :href "defenv.css" :rel "stylesheet"}]]
|
|
3185
|
+ [:body
|
|
3186
|
+ [:h1 header]
|
|
3187
|
+ (->> env-var->html
|
|
3188
|
+ env/extract-global-spec
|
|
3189
|
+ (reduce concat)
|
|
3190
|
+ (concat [:dl])
|
|
3191
|
+ (into []))]]))</pre></td></tr><tr><td class="docs"><p>Save the current global environment as an HTML file. The <code>header</code> will be
|
|
3192
|
+ emitted as an <code>h1</code> element at the top of the file. The <code>file-name</code> is where
|
|
3193
|
+ the contents will be saved.</p>
|
|
3194
|
+</td><td class="codes"><pre class="brush: clojure">(defn save-html
|
|
3195
|
+ [header file-name]
|
|
3196
|
+ (spit file-name (env->html header)))</pre></td></tr><tr><td class="docs"><h2>Example usage</h2>
|
|
3197
|
+</td><td class="codes"><pre class="brush: clojure">(defn- example []
|
|
3198
|
+ ;; Once you've loaded up the namespace that causes all the requisite
|
|
3199
|
+ ;; calls to `defenv` to be invoked...
|
|
3200
|
+ (require '[defenv.usage])
|
|
3201
|
+ ;; Then you can...
|
|
3202
|
+ (save-html "defenv environment specification" "test.html"))</pre></td></tr><tr><td class="spacer docs"> </td><td class="codes" /></tr></table><div class="footer">Generated by <a href="https://github.com/gdeer81/marginalia">Marginalia</a>. Syntax highlighting provided by Alex Gorbatchev's <a href="http://alexgorbatchev.com/SyntaxHighlighter/">SyntaxHighlighter</a><div id="floating-toc"><ul><li class="floating-toc-li" id="floating-toc_defenv.core">defenv.core</li><li class="floating-toc-li" id="floating-toc_defenv.usage">defenv.usage</li><li class="floating-toc-li" id="floating-toc_defenv.docs">defenv.docs</li></ul></div></div><script type="text/javascript">SyntaxHighlighter.defaults['gutter'] = false;
|
3161
|
3203
|
SyntaxHighlighter.all();
|
3162
|
3204
|
|
3163
|
3205
|
// hackity hack
|