configuro/
lib.rs

1//! This crate is a configuration library that loads and merges configuration YAML files
2//! using active profiles list passed by user.
3
4use core::str;
5
6use yaml_rust::Yaml;
7
8mod config_provider;
9mod local_config;
10pub mod profiles;
11mod yaml;
12
13pub use config_provider::ConfigProvider;
14
15
16/// Command which profiles to read and from
17pub struct ReadConfigFilesCommand<'a, T: AsRef<str>> {
18    pub(crate) profiles: &'a [T],
19    pub(crate) config_dir: &'a str,
20}
21
22impl<'a, T: AsRef<str>> ReadConfigFilesCommand<'a, T> {
23    pub fn new(profiles: &'a [T], config_dir: &'a str) -> ReadConfigFilesCommand<'a, T> {
24        ReadConfigFilesCommand {
25            profiles,
26            config_dir,
27        }
28    }
29}
30
31/// Scans `config_dir` looking for files matching pattern `application-*.yml` where `*` is an active
32/// profile specified in the command. Also `application.yml` is loaded as a base configuration that 
33/// is later on updated and extended with config from passed profiles.
34/// ```rust
35/// let yaml = configuro::read_yaml_config_from_files(
36///     &ReadConfigFilesCommand::new(&["profile1"], "config")
37/// );
38pub fn read_yaml_config_from_files<'a, T: AsRef<str>>(
39    command: &ReadConfigFilesCommand<'a, T>,
40) -> Yaml {
41    let lc = local_config::read_profiles_configs(command.profiles, command.config_dir);
42    yaml::parse_yaml_config(&lc)
43}