Function clientele::dotenv

source ·
pub fn dotenv() -> Result<PathBuf, Error>
Expand description

Loads the .env file from the current directory or parents. This is typically what you want.

If variables with the same names already exist in the environment, then their values will be preserved.

Where multiple declarations for the same environment variable exist in your .env file, the first one is applied.

If you wish to ensure all variables are loaded from your .env file, ignoring variables already existing in the environment, then use dotenv_override instead.

An error will be returned if the file is not found.

§Examples

dotenvy::dotenv()?;
Examples found in repository?
examples/skeleton/main.rs (line 31)
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
pub fn main() -> Result<(), SysexitsError> {
    // Load environment variables from `.env`:
    clientele::dotenv().ok();

    // Expand wildcards and @argfiles:
    let args = clientele::args_os()?;

    // Parse command-line options:
    let options = Options::parse_from(args);

    if options.flags.version {
        println!("skeleton {}", env!("CARGO_PKG_VERSION"));
        return Ok(());
    }

    if options.flags.license {
        println!("This is free and unencumbered software released into the public domain.");
        return Ok(());
    }

    match options.command {
        Command::Config {} => {
            println!("This is the implementation of the `config` subcommand.");
            Ok(())
        }
    }
}