diff --git a/examples/README.md b/examples/README.md index bf0219c7..146aa61b 100644 --- a/examples/README.md +++ b/examples/README.md @@ -283,7 +283,7 @@ which finds unused vars. It uses $ bb examples/hsqldb_unused_vars.clj src | :VARS/NS | :VARS/NAME | :VARS/FILENAME | :VARS/ROW | :VARS/COL | -|----------------------------+--------------------------+------------------------------------+-----------+-----------| +|----------------------------|--------------------------|------------------------------------|-----------|-----------| | babashka.impl.bencode.core | read-netstring | src/babashka/impl/bencode/core.clj | 162 | 1 | | babashka.impl.bencode.core | write-netstring | src/babashka/impl/bencode/core.clj | 201 | 1 | | babashka.impl.classes | generate-reflection-file | src/babashka/impl/classes.clj | 230 | 1 | @@ -345,3 +345,15 @@ $ examples/torrent-viewer.clj file.torrent ``` See [torrent-viewer.clj](torrent-viewer.clj). + +### [cprop.clj](cprop.clj) + +This script uses [tolitius/cprop](https://github.com/tolitius/cprop) library. + +See [cprop.clj](cprop.clj) + +Example usage: + +```shell +cd ./examples && chmod +x cprop.clj && ./cprop.clj +``` diff --git a/examples/cprop-override.properties b/examples/cprop-override.properties new file mode 100644 index 00000000..e07372ce --- /dev/null +++ b/examples/cprop-override.properties @@ -0,0 +1,12 @@ +datomic.url=datomic:sql://?jdbc:postgresql://localhost:5432/datomic?user=datomic&password=datomic + +source.account.rabbit.host=localhost + +aws.access-key=super secret key +aws.secret_key=super secret s3cr3t!!! +aws.region=us-east-2 + +io.http.pool.conn_timeout=42 +io.http.pool.max_per_route=42 + +other_things=1,2,3,4,5,6,7 \ No newline at end of file diff --git a/examples/cprop.clj b/examples/cprop.clj new file mode 100755 index 00000000..75fb2319 --- /dev/null +++ b/examples/cprop.clj @@ -0,0 +1,56 @@ +#!/usr/bin/env bb +(require '[babashka.classpath :refer [add-classpath]]) +(require '[clojure.java.shell :refer [sh]]) +(require '[clojure.pprint :refer [pprint]]) + +(def deps '{:deps {cprop {:mvn/version "0.1.17"}}}) +(def cp (:out (sh "clojure" "-Spath" "-Sdeps" (str deps)))) +(add-classpath cp) + +(require '[cprop.core :refer [load-config]]) +(require '[cprop.source :refer [from-props-file]]) + +;; Load sample configuration from the file system +(def conf (load-config :file "cprop.edn")) + +;; Print the configuration we just read in +(pprint conf) + +;;=> +#_{:datomic {:url "CHANGE ME"} + :aws {:access-key "AND ME" + :secret-key "ME TOO" + :region "FILL ME IN AS WELL" + :visiblity-timeout-sec 30 + :max-conn 50 + :queue "cprop-dev"} + :io {:http {:pool {:socket-timeout 600000 + :conn-timeout :I-SHOULD-BE-A-NUMBER + :conn-req-timeout 600000 + :max-total 200 + :max-per-route :ME-ALSO}}} + :other-things ["I am a vector and also like to place the substitute game"]} +(let [conf (load-config + :file "cprop.edn" + :merge [(from-props-file "cprop-override.properties")])] + (pprint conf)) + +;;=> +#_{:datomic + {:url "datomic:sql://?jdbc:postgresql://localhost:5432/datomic?user=datomic&password=datomic"}, + :aws + {:access-key "super secret key", + :secret-key "super secret s3cr3t!!!", + :region "us-east-2", + :visiblity-timeout-sec 30, + :max-conn 50, + :queue "cprop-dev"}, + :io + {:http + {:pool + {:socket-timeout 600000, + :conn-timeout 42, + :conn-req-timeout 600000, + :max-total 200, + :max-per-route 42}}}, + :other-things ["1" "2" "3" "4" "5" "6" "7"]} diff --git a/examples/cprop.edn b/examples/cprop.edn new file mode 100644 index 00000000..db5da92c --- /dev/null +++ b/examples/cprop.edn @@ -0,0 +1,26 @@ +#_ +{:datomic + {:url "datomic:sql://?jdbc:postgresql://localhost:5432/datomic?user=datomic&password=datomic"} + :source + {:account + {:rabbit + {:host "127.0.0.1" + :port 5672 + :vhost "/z-broker" + :username "guest" + :password "guest"}}} + :answer 42} + +{:datomic {:url "CHANGE ME"} + :aws {:access-key "AND ME" + :secret-key "ME TOO" + :region "FILL ME IN AS WELL" + :visiblity-timeout-sec 30 + :max-conn 50 + :queue "cprop-dev"} + :io {:http {:pool {:socket-timeout 600000 + :conn-timeout :I-SHOULD-BE-A-NUMBER + :conn-req-timeout 600000 + :max-total 200 + :max-per-route :ME-ALSO}}} + :other-things ["I am a vector and also like to place the substitute game"]}