diff --git a/deps.edn b/deps.edn index fedfe577..61664cd3 100644 --- a/deps.edn +++ b/deps.edn @@ -81,7 +81,8 @@ rm-hull/jasentaa {:mvn/version "0.2.5"} slingshot/slingshot {:mvn/version "0.12.2"} io.replikativ/hasch {:mvn/version "0.3.7"} - com.grammarly/omniconf {:mvn/version "0.4.3"}} + com.grammarly/omniconf {:mvn/version "0.4.3"} + crispin/crispin {:mvn/version "0.3.8"}} :classpath-overrides {org.clojure/clojure nil org.clojure/spec.alpha nil org.clojure/core.specs.alpha nil}} diff --git a/doc/projects.md b/doc/projects.md index 3f70ff57..2a337adb 100644 --- a/doc/projects.md +++ b/doc/projects.md @@ -40,6 +40,9 @@ The following libraries and projects are known to work with babashka. - [rewrite-edn](#rewrite-edn) - [expound](#expound) - [omniconf](#omniconf) + - [slingshot](#slingshot) + - [hasch](#hasch) + - [crispin](#crispin) - [Pods](#pods) - [Projects](#projects-1) - [babashka-test-action](#babashka-test-action) @@ -598,6 +601,33 @@ NOTE: hasch's tests pass with babashka except the test around hashing records. This is due to a difference in how records are implemented in babashka. This may be fixed later if this turns out to be really useful. +### [crispin](https://github.com/dunaj-project/crispin) + +Populate a configuration map from multiple sources (environment variables, +system variables, config files, etc.) + +Example: + +script.clj +``` clojure +#!/usr/bin/env bb + +(ns script + (:require [babashka.deps :as deps])) + +(deps/add-deps + '{:deps {crispin/crispin {:mvn/version "0.3.8"}}}) + +(require '[crispin.core :as crispin]) +(def app-cfg (crispin/cfg)) +(app-cfg :foo) +``` + +``` text +FOO=1 script.clj +"1" +``` + ## Pods [Babashka pods](https://github.com/babashka/babashka.pods) are programs that can diff --git a/test-resources/lib_tests/babashka/run_all_libtests.clj b/test-resources/lib_tests/babashka/run_all_libtests.clj index 723ad4ee..44a6ebe3 100644 --- a/test-resources/lib_tests/babashka/run_all_libtests.clj +++ b/test-resources/lib_tests/babashka/run_all_libtests.clj @@ -223,6 +223,8 @@ (test-namespaces 'omniconf.core-test) +(test-namespaces 'crispin.core-test) + ;;;; final exit code (let [{:keys [:test :fail :error] :as m} @status] diff --git a/test-resources/lib_tests/crispin/core_test.clj b/test-resources/lib_tests/crispin/core_test.clj new file mode 100644 index 00000000..fbb6e7f6 --- /dev/null +++ b/test-resources/lib_tests/crispin/core_test.clj @@ -0,0 +1,22 @@ +(ns crispin.core-test + (:require [clojure.test :refer [deftest is testing]] + [crispin.core :as cfg])) + +(deftest crispin.core-test + (testing "config from multiple sources" + (do + (cfg/load-custom-cfg! "test-resources/lib_tests/crispin" "crispin-test-custom-cfg.edn") + (System/setProperty "crispintest.value" "yes") + (System/setProperty "crispin" "test-resources/lib_tests/crispin/crispin-test-cfg.edn") + (let [c (cfg/cfg)] + ; something from the environment + (is (not-empty (cfg/sget c :path))) + ; things from the resource named by the :crispin property + (is (= "pina colada" (cfg/sget-in c [:likes 0]))) + (is (= 3.14 (cfg/nget-in c [:crispintest :pi]))) + ; something from system properties + (is (true? (cfg/bget-in c [:crispintest :value]))) + ; something from load-custom-cfg! file + (is (= :bar (:foo c)))) + (System/clearProperty "crispintest.value") + (System/clearProperty "crispin")))) diff --git a/test-resources/lib_tests/crispin/crispin-test-cfg.edn b/test-resources/lib_tests/crispin/crispin-test-cfg.edn new file mode 100644 index 00000000..303c2ac9 --- /dev/null +++ b/test-resources/lib_tests/crispin/crispin-test-cfg.edn @@ -0,0 +1,2 @@ +{:crispintest {:pi 3.14} + :likes ["pina colada" "getting caught in the rain"]} diff --git a/test-resources/lib_tests/crispin/crispin-test-custom-cfg.edn b/test-resources/lib_tests/crispin/crispin-test-custom-cfg.edn new file mode 100644 index 00000000..cf1c0f08 --- /dev/null +++ b/test-resources/lib_tests/crispin/crispin-test-custom-cfg.edn @@ -0,0 +1 @@ +{:foo :bar}