Last active
August 10, 2018 17:23
-
-
Save emidln/024da988425c3654c856675b5eaf4b71 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
(require '[clojure.spec.alpha :as s]) | |
(require '[spec-tools.spec :as spec]) | |
(require '[spec.settings :as ss]) | |
;; declare your configuration | |
(def settings-config | |
{:debug {:spec spec/boolean? | |
:doc "When true, debug options are turned on." | |
:default false} | |
:num-processes {:spec spec/integer? | |
:doc "Number of processes to map over" | |
:default 4} | |
:fav-color {:spec spec/string? | |
:doc "Your favorite color."} | |
:foo {:spec spec/string? | |
:doc "Foo; not Bar, Baz, or Qux" | |
:default "foo"}}) | |
;; specify your config | |
(s/def ::settings (ss/settings-spec ::settings settings-config)) | |
;; you'd normally set these via environment or at app startup | |
(System/setProperty "sampleapp.debug" "true") | |
(System/setProperty "sampleapp.num.processes" "2") | |
(System/setProperty "sampleapp.fav.color" "blue") | |
;; validate your settings | |
(= (ss/validate-settings! ::settings (ss/all-settings settings-config "sampleapp")) | |
{:debug true | |
:num-processes 2 | |
:fav-color "blue" | |
:foo "foo"}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment