### Example cprop Configuration Map - Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md This Clojure map represents a sample application configuration structure used throughout the examples to demonstrate cprop's features. ```Clojure {: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} ``` -------------------------------- ### Example .properties File (Properties) Source: https://github.com/tolitius/cprop/blob/master/README.md An example of a .properties file content used with the `slurp-props-file` function, showing key-value pairs where keys might contain dots. ```properties {"star" "sun", "planet.jupiter.moons" "io,europa,ganymede,callisto", "planet.neptune.moons" "triton", "planet.jupiter.orbit_days" "4332.59", "planet.uran.orbit_days" "30688.5", "planet.venus.orbit_days" "224.7", "planet.earth.moons" "moon", "planet.saturn.orbit_days" "10755.7", "planet.mercury.orbit_days" "87.969", "planet.saturn.moons" "titan", "planet.earth.orbit_days" "365.2564", "planet.uran.moons" "titania,oberon", "planet.mars.orbit_days" "686.93", "planet.neptune.orbit_days" "60148.35" "dwarf.pluto.moons" "charon,styx,nix,kerberos,hydra", "components" "sun,planets,dwarf planets,moons,comets,asteroids,meteoroids,dust,atomic particles,electromagnetic.radiation,magnetic field"} ``` -------------------------------- ### Example .env File Content for cprop Source: https://github.com/tolitius/cprop/blob/master/README.md Provides an example of a `.env` file structure, illustrating comments, simple key-value pairs, and keys using cprop's namespace/nested key conventions for loading configuration. ```bash # this is a comment SIMPLE=simple HYPHEN_KEY=hyphen-key EMPTY_KEY= ## this is another comment DOTTED.KEY=dotted.key NAMSPACED___KEY=namespaced/key SUPER__NESTED__KEY=super nested key ``` -------------------------------- ### Example Configuration Map Structure - Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md This snippet shows an example of the nested map structure returned by the `load-config` function, illustrating how configuration data is organized. ```clojure {: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} ``` -------------------------------- ### Example Clojure Configuration Map Source: https://github.com/tolitius/cprop/blob/master/README.md Defines a sample configuration map in Clojure with placeholder values that are intended to be overridden by environment variables or other sources. ```clojure {: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 play the substitute game"]} ``` -------------------------------- ### Comprehensive Configuration Loading and Merging - Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md This snippet provides a comprehensive example combining multiple configuration sources and merge options, including specific resources/files, custom maps, properties files, system properties, and environment variables. ```clojure (load-config :resource "path/within/classpath/to.edn" :file "/path/to/some.edn" :merge [{:datomic {:url "foo.bar"}} (from-file "/path/to/another.edn") (from-resource "path/within/classpath/to-another.edn") (parse-runtime-args ...) (from-props-file "/path/to/some.properties") (from-system-props) (from-env)]) ``` -------------------------------- ### Environment Variable Type Conversion Examples (Bash) Source: https://github.com/tolitius/cprop/blob/master/README.md Shows examples of different environment variable values and how cprop attempts to convert them to appropriate data types (Long, String, EDN) when loading configuration. ```bash export APP_HTTP_PORT=4242 export APP_DB_URL=jdbc:sqlite:order.db export APP_DB_URL='jdbc:sqlite:order.db' export APP_DB_URL="jdbc:sqlite:order.db" export APP_NUMS='[1 2 3 4]' ``` -------------------------------- ### Using Cursors to Navigate Loaded Config in Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md This example demonstrates how to use the `cursor` function to create a focused view into a nested part of the loaded configuration map. This simplifies accessing deeply nested values by providing a starting point for subsequent lookups, avoiding repetitive use of `get-in` or nested map access. ```clojure (def conf (load-config)) (def rabbit (cursor conf :source :account :rabbit)) (rabbit :vhost) ``` -------------------------------- ### Setting Nested System Property (Bash) Source: https://github.com/tolitius/cprop/blob/master/README.md Example of setting a system property from the command line using the `-D` flag, demonstrating how `.` and `_` map to nested configuration keys in cprop. ```bash -Dhttp_pool_socket.timeout=4242 ``` -------------------------------- ### Setting Nested System Property (Java) Source: https://github.com/tolitius/cprop/blob/master/README.md Example of setting a system property programmatically in Java, demonstrating how `.` and `_` map to nested configuration keys in cprop. ```java System.setProperty("http_pool_socket.timeout" "4242"); ``` -------------------------------- ### Example cprop Debug Output (Clojure) Source: https://github.com/tolitius/cprop/blob/master/README.md Shows the output produced by cprop when the DEBUG environment variable is set, listing the configuration files read and the properties that were substituted from environment variables or system properties. ```clojure user=> (load-config) read config from stream: "dev-resources/config.edn" ;; read config from file: "dev-resources/config.edn" ;; => a sample output read config from resource: "config.edn" ;; substituting [:aws :region] with a ENV/system.property specific value substituting [:aws :secret-key] with a ENV/system.property specific value substituting [:io :http :pool :conn-timeout] with a ENV/system.property specific value substituting [:io :http :pool :max-per-route] with a ENV/system.property specific value substituting [:datomic :url] with a ENV/system.property specific value substituting [:aws :access-key] with a ENV/system.property specific value substituting [:other-things] with a ENV/system.property specific value ;; ... ``` -------------------------------- ### Demonstrating EDN Read Failures in Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md These snippets show examples where clojure.edn/read-string fails or produces unexpected results when attempting to parse strings that are not valid EDN, such as dates or strings starting with numbers followed by non-numeric characters. This highlights the need for alternative parsing methods like cprop's ':as-is?' flag. ```clojure => (require '[clojure.edn :as edn]) => (edn/read-string "7 Nov 22:44:53 2015") 7 ``` ```clojure boot.user=> (edn/read-string "7Nov 22:44:53 2015") java.lang.NumberFormatException: Invalid number: 7Nov ``` -------------------------------- ### Converting Properties File to EDN Map (Clojure) Source: https://github.com/tolitius/cprop/blob/master/README.md Shows how to use the from-props-file function to read a .properties file and convert its content directly into a Clojure EDN map, without necessarily merging it into the global configuration. This is useful for inspecting or processing properties data programmatically. The example uses a 'solar-system.properties' file. ```clojure (from-props-file "solar-system.properties") ``` -------------------------------- ### Merging Properties File into cprop Config (Clojure) Source: https://github.com/tolitius/cprop/blob/master/README.md Demonstrates how to load configuration from a .properties file using from-props-file and merge it into the main configuration map managed by load-config. This allows overriding values from other sources like EDN files, system properties, or environment variables. The example shows merging an 'overrides.properties' file. ```clojure (require '[cprop.source :refer [from-props-file]]) (load-config :merge [(from-props-file "path-to/overrides.properties")]) ``` ```clojure (load-config :merge [(from-props-file "overrides.properties")]) ``` -------------------------------- ### Setting Nested Environment Variable (Bash) Source: https://github.com/tolitius/cprop/blob/master/README.md Example of setting an environment variable in Bash to override a nested configuration value, showing the use of double underscores (`__`) for nesting and single underscores (`_`) for dashes. ```bash export HTTP__POOL__SOCKET_TIMEOUT=4242 ``` -------------------------------- ### Setting Environment Variables for cprop Testing Source: https://github.com/tolitius/cprop/blob/master/README.md This bash script exports several environment variables with different types of values, including quoted strings, numbers, dates, and EDN-like vectors. These variables are used in subsequent Clojure examples to demonstrate how cprop reads them with and without the ':as-is?' option. ```bash $ export FOO='"4242"' $ export BAR=4242 $ export DATE='7 Nov 22:44:53 2015' $ export VEC='[1 2 3 4]' ``` -------------------------------- ### Creating a Basic Configuration Cursor - Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md Demonstrates how to create a basic cursor pointing to a specific key within the configuration map using the `cursor` function. The cursor can then be invoked as a function to retrieve values. ```Clojure user=> (def src (cursor conf :source)) #'user/src user=> (src) {:account {:rabbit {:host "127.0.0.1", :port 5672, :vhost "/z-broker", :username "guest", :password "guest"}}} user=> (src :account) {:rabbit {:host "127.0.0.1", :port 5672, :vhost "/z-broker", :username "guest", :password "guest"}} ``` -------------------------------- ### Composing a Cursor from Another Cursor - Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md Shows how to create a new cursor (`account`) by composing it from an existing cursor (`src`) and an additional key (`:account`). This allows navigating deeper into the configuration structure. ```Clojure user=> (def account (cursor conf src :account)) #'user/account user=> (account :rabbit) {:host "127.0.0.1", :port 5672, :vhost "/z-broker", :username "guest", :password "guest"} ``` -------------------------------- ### Loading Configuration from Both Resource and File Path in Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md Shows how to combine loading configuration from both a classpath resource and a file system path using the `:resource` and `:file` options. Properties from the file path will override those from the resource before merging with system properties and environment variables. ```Clojure (load-config :resource "path/within/classpath/to-some.edn" :file "/path/to/another.edn") ``` -------------------------------- ### Loading and Merging Config with ENV Variables in Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md Demonstrates loading the configuration using `cprop/load-config` after environment variables have been set, showing the console output indicating substitutions and the resulting merged configuration map. ```clojure user=> (load-config) substituting [:aws :region] with a ENV/system.property specific value substituting [:aws :secret-key] with a ENV/system.property specific value substituting [:io :http :pool :conn-timeout] with a ENV/system.property specific value substituting [:io :http :pool :max-per-route] with a ENV/system.property specific value substituting [:datomic :url] with a ENV/system.property specific value substituting [:aws :access-key] with a ENV/system.property specific value substituting [:other-things] with a ENV/system.property specific value {:datomic {:url "datomic:sql://?jdbc:postgresql://localhost:5432/datomic?user=datomic&password=datomic"}, :aws {:access-key "AKIAIOSFODNN7EXAMPLE", :secret-key "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", :region "us-east-1", :visiblity-timeout-sec 30, :max-conn 50, :queue "cprop-dev"}, :io {:http {:pool {:socket-timeout 600000, :conn-timeout 60000, :conn-req-timeout 600000, :max-total 200, :max-per-route 10}}}, :other-things [1 2 3 "42"]} ``` -------------------------------- ### Load Default Configuration - Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md This snippet shows the simplest way to load configuration using `load-config` with no arguments. It loads and merges configurations from default sources (classpath and file system). ```clojure (load-config) ``` -------------------------------- ### Loading Default Configuration in Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md Demonstrates the basic usage of `cprop.core/load-config` to load the default configuration. This includes merging from classpath `config.edn`, file system (via `conf` system property), system properties, and environment variables. ```Clojure (require '[cprop.core :refer [load-config]]) (load-config) ``` -------------------------------- ### Merging All System Properties (Clojure) Source: https://github.com/tolitius/cprop/blob/master/README.md Demonstrates how to configure cprop to merge *all* system properties into the configuration using `load-config` with the `:merge` option and `from-system-props`. ```clojure (require '[cprop.source :refer [from-system-props]]) (load-config :merge [(from-system-props)]) ``` -------------------------------- ### Combine Resource, File, and Merge Options - Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md This snippet shows how to combine the `:resource`, `:file`, and `:merge` options in a single `load-config` call. This allows loading configuration from specific default sources and then merging additional maps from various origins. ```clojure (load-config :resource "path/within/classpath/to.edn" :file "/path/to/some.edn" :merge [{:datomic {:url "foo.bar"}} (from-file "/path/to/another.edn") (from-resource "path/within/classpath/to-another.edn") (parse-runtime-args ...)]) ``` -------------------------------- ### Merge System Properties and ENV Vars with Configuration - Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md This snippet shows how to use the `:merge` option with both `from-system-props` and `from-env` to include all system properties and environment variables in the configuration map. ```clojure (load-config :merge [(from-system-props) (from-env)]) ``` -------------------------------- ### Loading Config with Selective 'as is' Paths in Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md This snippet demonstrates using the ':as-is-paths' option with `load-config`. This allows specifying a set of key paths (as vectors of keywords) for which the values should be read 'as is' (as strings), while other values in the configuration are still subject to default EDN parsing. ```clojure (load-config :as-is-paths #{[:io :http :pool :socket-timeout] [:datomic :max-conn] [:some :other :path]}) ``` -------------------------------- ### Loading All Config 'as is' in Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md This snippet shows how to apply the ':as-is? true' flag at the top level when loading configuration using `load-config`. This forces cprop to read all properties and config values as raw strings, bypassing EDN parsing for the entire configuration tree. ```clojure (load-config :as-is? true) ``` -------------------------------- ### Loading and Merging Config from .env File in Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md Shows how to use `cprop.source/from-env-file` with `cprop/load-config` to load configuration values specifically from a specified `.env` file. ```clojure (require '[cprop.core :as cp] '[cprop.source :as cs]) (cp/load-config :merge [(cs/from-env-file "dev-resources/.env")]) ;; {:empty-key "", ;; :simple "simple", ;; :super {:nested {:key "super nested key"}}, ;; :namspaced/key "namespaced/key", ;; :source {:account {:rabb...}} ;; ...} ``` -------------------------------- ### Load Configuration and Access Values - Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md This snippet shows how to load the default configuration using `load-config` and then access values from the resulting map using keyword lookup and `get-in` for nested properties. ```clojure (def conf (load-config)) (conf :answer) ;; 42 (get-in conf [:source :account :rabbit :vhost]) ;; "/z-broker" ``` -------------------------------- ### Setting 'conf' System Property in Boot - Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md Shows how to set the Java system property `conf` programmatically within a Boot build file using `System/setProperty`. This specifies the configuration file path for cprop. ```Clojure (System/setProperty "conf" "resources/config.edn") ``` -------------------------------- ### Use slurp-props-file (Clojure) Source: https://github.com/tolitius/cprop/blob/master/README.md Demonstrates how to require the `cprop.source` namespace and use the `slurp-props-file` function to read a .properties file into a flat map, without parsing values or building a hierarchy. ```clojure (require '[cprop.source :refer [slurp-props-file]]) (slurp-props-file "solar-system.properties") ``` -------------------------------- ### Loading Configuration from Specific File Path in Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md Illustrates how to load configuration from a specific file path on the file system using the `:file` option in `load-config`. This overrides the default file system path identified by the `conf` system property. ```Clojure (load-config :file "/path/to/another.edn") ``` -------------------------------- ### Composing a Nested Cursor - Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md Illustrates creating a deeply nested cursor (`rabbit`) by composing it from an existing cursor (`src`) and multiple keys (`:account :rabbit`). The resulting cursor directly accesses the target configuration subtree. ```Clojure user=> (def rabbit (cursor conf src :account :rabbit)) #'user/rabbit user=> (rabbit :host) "127.0.0.1" ``` -------------------------------- ### Merge System Properties with Configuration - Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md This snippet demonstrates using the `:merge` option with `from-system-props` to include all system properties in the configuration map. This allows system properties to add or override values. ```clojure (load-config :merge [(from-system-props)]) ``` -------------------------------- ### Merging All Environment Variables (Clojure) Source: https://github.com/tolitius/cprop/blob/master/README.md Demonstrates how to configure cprop to merge *all* environment variables into the configuration using `load-config` with the `:merge` option and `from-env`. ```clojure (require '[cprop.source :refer [from-env]]) (load-config :merge [(from-env)]) ``` -------------------------------- ### Merge Configuration from Various Sources - Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md This snippet demonstrates using the `:merge` option with maps obtained from different sources, including literal maps, files, and resources. It shows how the merge order affects the final configuration values. ```clojure (load-config :merge [{:datomic {:url "foo.bar"}} (from-file "/path/to/another.edn") (from-resource "path/within/classpath/to.edn") {:datomic {:url "this.will.win"}} ]) ``` -------------------------------- ### Loading Configuration from Specific Classpath Resource in Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md Shows how to load configuration specifically from a resource file located within the classpath using the `:resource` option in `load-config`. This overrides the default classpath resource. ```Clojure (load-config :resource "path/within/classpath/to-some.edn") ``` -------------------------------- ### Require cprop.core - Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md This snippet demonstrates how to require the `cprop.core` namespace and refer to the `load-config` function, making it available for use. ```clojure (require '[cprop.core :refer [load-config]]) ``` -------------------------------- ### Require System Property and ENV Source Functions - Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md This snippet shows how to require the `cprop.source` namespace to access functions like `from-system-props` and `from-env`, which are used to obtain configuration maps from system properties and environment variables. ```clojure (require '[cprop.source :refer [from-system-props from-env]]) ``` -------------------------------- ### Loading Config with a Custom Key Parsing Function in Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md This snippet shows how to use the `:key-parse-fn` option with `load-config`, passing the previously defined `parse-numbers` function. This allows cprop to use the custom logic when parsing key paths, enabling correct handling of numeric keys in nested structures derived from sources like environment variables. ```clojure => (load-config :key-parse-fn parse-numbers) {:clusters [{:name "first" :url "http://somewhere" :password "super-duper-secret"} {:name "second" :url "http://elsewhere" :password "shh-don't-tell"}]} ``` -------------------------------- ### Converting EDN Config to .properties File - Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md Uses the `map->props-file` function from `cprop.tools` to convert a Clojure configuration map into a temporary file formatted as Java `.properties`. The function returns the path to the created file. ```Clojure (t/map->props-file config) ``` -------------------------------- ### Setting 'conf' System Property in Leiningen - Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md Illustrates how to set the Java system property `conf` within a Leiningen `project.clj` file by adding it to the `:jvm-opts` vector in a profile. This configures the JVM to load the specified configuration file. ```Clojure :profiles {:dev {:jvm-opts ["-Dconf=resources/config.edn"]}} ``` -------------------------------- ### Require cprop.source Functions - Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md This snippet shows how to require the `cprop.source` namespace to access functions like `from-file` and `from-resource`, which are used to obtain configuration maps from specific sources. ```clojure (require '[cprop.source :refer [from-file from-resource]]) ``` -------------------------------- ### Merge Custom Maps with Configuration - Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md This snippet illustrates using the `:merge` option with `load-config` to merge a sequence of custom maps into the default configuration. The maps are merged in the order provided, with later maps overriding earlier ones. ```clojure (load-config :merge [{:datomic {:url "foo.bar"}} {:some {:other {:property :to-merge}}}]) ``` -------------------------------- ### Requiring cprop.tools Namespace - Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md This line of code requires the `cprop.tools` namespace, which contains utility functions for configuration management, such as converting configuration maps to different file formats. ```Clojure (require '[cprop.tools :as t]) ``` -------------------------------- ### Override Configuration with :override-with - Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md This snippet demonstrates using the `:override-with` option in `load-config`. The map provided to this option takes the highest precedence and overrides any matching values from all other configuration sources. ```clojure => (load-config :override-with {:datomic {:url "bar"}}) {:datomic {:url "bar"}, :source ... } ``` -------------------------------- ### Setting 'conf' System Property via Command Line - Shell Source: https://github.com/tolitius/cprop/blob/master/README.md Demonstrates how to set the Java system property `conf` using the `-D` flag when launching a Java application from the command line. This property is used by cprop to locate the configuration file. ```Shell java -Dconf="../somepath/whatsapp.conf" -jar whatsapp.jar ``` -------------------------------- ### Reading Environment Variables With ':as-is?' in Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md This Clojure code demonstrates reading environment variables using cprop's `from-env` function with the ':as-is? true' flag. This flag instructs cprop to treat the variable values as raw strings, preventing EDN parsing and preserving the original format, which is useful for non-EDN values. ```clojure => (:foo (s/from-env {:as-is? true})) "\"4242\"" => (:bar (s/from-env {:as-is? true})) "4242" => (:date (s/from-env {:as-is? true})) "7 Nov 22:44:53 2015" => (:vec (s/from-env {:as-is? true})) "[1 2 3 4]" ``` -------------------------------- ### Converting EDN Config to .env File - Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md Uses the `map->env-file` function from `cprop.tools` to convert a Clojure configuration map into a temporary file formatted for shell environment variables (`.env`). The function returns the path to the created file. ```Clojure (t/map->env-file config) ``` -------------------------------- ### Exporting Environment Variables for cprop Merging Source: https://github.com/tolitius/cprop/blob/master/README.md Shows how to export environment variables in Bash using the double-underscore `__` convention recognized by cprop to target nested configuration keys for substitution. ```bash export AWS__ACCESS_KEY=AKIAIOSFODNN7EXAMPLE export AWS__SECRET_KEY="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" export AWS__REGION='us-east-1' export IO__HTTP__POOL__CONN_TIMEOUT=60000 export IO__HTTP__POOL__MAX_PER_ROUTE=10 export OTHER__THINGS='[1 2 3 "42"]' ``` -------------------------------- ### Enable cprop Debugging (Bash) Source: https://github.com/tolitius/cprop/blob/master/README.md Sets the DEBUG environment variable to 'y' to enable verbose output from the cprop library, showing file loading and property substitutions. ```bash export DEBUG=y ``` -------------------------------- ### Requiring cprop Cursor Functionality in Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md This snippet shows the standard way to require the necessary functions, `load-config` and `cursor`, from the `cprop.core` namespace in Clojure. This is a prerequisite for using the cursor feature to navigate loaded configuration maps. ```clojure (require '[cprop.core :refer [load-config cursor]]) ``` -------------------------------- ### Load Configuration with ENV Override - Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md This snippet shows the result of loading configuration after an environment variable (`DATOMIC__URL`) has been set. cprop automatically uses matching environment variables to override default values. ```clojure => (load-config) {:datomic {:url "foo"}, :source ... } ``` -------------------------------- ### Set Environment Variable for Override - Bash Source: https://github.com/tolitius/cprop/blob/master/README.md This snippet shows how to set an environment variable in Bash. cprop can pick up environment variables (especially those matching configuration keys) to override default values. ```bash $ export DATOMIC__URL=foo ``` -------------------------------- ### Reading Environment Variables Without ':as-is?' in Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md This Clojure code demonstrates reading environment variables using cprop's `from-env` function without the ':as-is?' flag. By default, cprop attempts to parse values as EDN, which can lead to incorrect parsing for non-EDN strings like dates or quoted strings. ```clojure => (require '[cprop.source :as s]) => (:foo (s/from-env)) "4242" => (:bar (s/from-env)) 4242 => (:date (s/from-env)) 7 => (:vec (s/from-env)) [1 2 3 4] ``` -------------------------------- ### Defining a Custom Key Parsing Function in Clojure Source: https://github.com/tolitius/cprop/blob/master/README.md This Clojure function, `parse-numbers`, is designed to be used as a custom `:key-parse-fn` for cprop. It checks if a key path part is a number string and converts it to a long; otherwise, it converts it to a keyword. This is useful for handling configuration structures where keys represent list indices or numeric identifiers. ```clojure => (def parse-numbers [part] (if (re-matches #"\d+" part) (long part) (keyword part))) ``` -------------------------------- ### Forcing String Type for Numeric Value (Bash) Source: https://github.com/tolitius/cprop/blob/master/README.md Shows how to force cprop to treat a purely numeric string environment variable as a String by enclosing the value in double quotes within the export command. ```bash export BAD_PASSWORD='"123456789"' ``` -------------------------------- ### Numeric String Type Conversion Caveat (Bash) Source: https://github.com/tolitius/cprop/blob/master/README.md Illustrates a caveat where a purely numeric string environment variable might be incorrectly converted to a number (Long) by cprop instead of remaining a String. ```bash export BAD_PASSWORD='123456789' ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.