#env-var #nested #clap #parser #string #value

nested-env-parser

Nested Env Parser is a crate for getting the final value of a string with nested environment variables

2 stable releases

1.1.0 May 31, 2023
1.0.0 May 12, 2023

#42 in #nested

Download history 28/week @ 2024-02-12 17/week @ 2024-02-19 21/week @ 2024-02-26 17/week @ 2024-03-11 42/week @ 2024-04-01

59 downloads per month
Used in mongodb-macro

MIT license

7KB
69 lines

crates.io documentation MIT License

nested-env-parser

Nested Env Parser is a crate for getting the final value of a string with nested environment variables.

installation

Install using cargo:

cargo install nested-env-parser

Usage

On Unix

use clap::Parser;
use nested_env_parser::Env;

#[derive(Clone, Debug, Parser)]
struct Opts {
    #[clap(env)]
    value_with_env: Env,
}

fn main() {
    std::env::set_var("VALUE1", "Hello,");
    std::env::set_var("VALUE2", "world");
    std::env::set_var("VALUE_WITH_ENV", "$VALUE1 ${VALUE2}!");

    let opts = Opts::parse();

    assert_eq!("Hello, world!", &opts.value_with_env);
}

On Windows

use clap::Parser;
use nested_env_parser::Env;

#[derive(Clone, Debug, Parser)]
struct Opts {
    #[clap(env)]
    value_with_env: Env,
}

fn main() {
    std::env::set_var("VALUE1", "Hello");
    std::env::set_var("VALUE2", "world");
    std::env::set_var("VALUE_WITH_ENV", "%VALUE1%, %VALUE2%!");

    let opts = Opts::parse();

    assert_eq!("Hello, world!", &opts.value_with_env);
}

Current version: 1.1.0

License: MIT

Dependencies

~3.5MB
~21K SLoC