Skip to main content

Crate config_shellexpand

Crate config_shellexpand 

Source
Expand description

§Config Shellexpand

An extension marrying config with shellexpand to allow expansion of environment variables in configuration files.

§How do I use this thing?

Instead of adding files as sources when building your config, add config_shellexpand::TemplatedFile instead.

Variable substitution will then be performed when your file is sourced.

use config_shellexpand::TemplatedFile;
use rxpect::expect;
use rxpect::expectations::EqualityExpectations;
use serde::Deserialize;

#[derive(Deserialize)]
struct Config {
    package_name: String,
}

let config: Config = config::Config::builder()
    /*
     * Add a config file with contents like:
     * package_name = "${CARGO_PKG_NAME}"
    */
    .add_source(TemplatedFile::with_name(path))
    .build()
    .unwrap()
    .try_deserialize()
    .unwrap();

expect(config.package_name).to_equal("config-shellexpand".to_string());

Structs§

TemplatedFile
Configuration source that expands shell variables in files

Traits§

Context
Context for variable substitution Used by shellexpand to resolve variable values