salak-0.4.0 has been yanked.
salak
A layered configuration loader with zero-boilerplate configuration management.
About
salak try to provide an out-of-box configuration loader for creating new apps, such as cli, web, servers.
Multi-Layered source environment.
salak defines following default PropertySources:
- Command line arguments using
clapto parsing-P, --propery KEY=VALUE. - System Environment.
- app.toml(*) in current dir and $HOME dir. Or if you specify
APP_CONF_DIRdir, then only load toml in this dir.
* APP_CONF_NAME can be specified to replace app.
Placeholder format
${key:default}means get value ofkey, if not exists then returndefault.${key}means get value ofkey, if not exists then returnPropertyError::NotFound(_).
Key format
a.b.cis a normal key separated by dot(.).a.b[0],a.b[1],a.b[2]... is a group of keys with arrays.- System environment key will be changed from
HELLO_WORLD<=>hello.world,HELLO__WORLD_HOW<=>hello_world.how,hello[1].world=>HELLO_1_WORLD<=>hello.1.world.
Auto derived parameters.
attribute default to set default value.
#[salak(default="string")]#[salak(default=1)]
attribute disable_placeholder to disable placeholder parsing.
#[salak(disable_placeholder)]#[salak(disable_placeholder = true)]
Features
Default features
enable_log, enable log record if enabled.enable_toml, enable toml support.enable_derive, enable auto derive [FromEnvironment] for struts.
Optional features
enable_clap, enable default command line arguments parsing byclap.
Quick Code
use *;
// Output: DatabaseConfig { url: "localhost:5432", name: "salak", username: "salak", password: None, description: "${Hello}" }
Quick Run
# salak 0.4.0
# Daniel Yu <leptonyu@gmail.com>
# A rust configuration loader
#
# USAGE:
# salak [OPTIONS]
#
# FLAGS:
# -h, --help Prints help information
# -V, --version Prints version information
#
# OPTIONS:
# -P, --property <KEY=VALUE>... Set properties
TODO
- Support hashmap.
- Reload configurations.