/// Returns a HashMap that aggregates all environment variables for
/// a context within a git branch.
///
/// # Arguments
///
/// `ctx` - The context name, for example `deploy-preview`, `branch-deploy` or `production`.
/// `branch` - The deploy branch name, for example `make-changes-to-my-site`.
///
/// # Example
///
/// ```
/// let io = r#"
/// [build]
///   command = "make site"
/// "#;
///
/// let config = netlify_toml::from_str(io).unwrap();
/// let env = config.context_env("deploy-preview", "new-styles");
/// ```
Returns a HashMap that aggregates all environment variables for
a context within a git branch.
Returns a HashMap that aggregates all environment variables for a context within a git branch .
pub fn context_env(self, ctx: &str, branch: &str) -> HashMap<String, String> {
        let mut result = HashMap::new();
        // Read the env variables from the global "build" context.
        if let Some(c) = self.build {
            if let Some(ref env) = c.environment {
                for (k, v) in env {
                    result.insert(k.to_string(), v.to_string());
                }
            }
        }
        if let Some(c) = self.context {
            // Override with default context environment,
            // like `deploy-preview`, `branch-deploy` or `production`.
            if let Some(x) = c.get(ctx) {
                if let Some(ref env) = x.environment {
                    for (k, v) in env {
                        result.insert(k.to_string(), v.to_string());
                    }
                }
            }
            // Override with branch context environment,
            // like `deploy-preview`, `branch-deploy` or `production`.
            if let Some(x) = c.get(branch) {
                if let Some(ref env) = x.environment {
                    for (k, v) in env {
                        result.insert(k.to_string(), v.to_string());
                    }
                }
            }
        }
        result
    }
pub fn context_env ( self , ctx : & str , branch : & str ) -> HashMap < String , String > { let mut result = HashMap :: new ( ) ; // Read the env variables from the global "build" context. if let Some ( c ) = self . build { if let Some ( ref env ) = c . environment { for ( k , v ) in env { result . insert ( k . to_string ( ) , v . to_string ( ) ) ; } } } if let Some ( c ) = self . context { // Override with default context environment, // like `deploy-preview`, `branch-deploy` or `production`. if let Some ( x ) = c . get ( ctx ) { if let Some ( ref env ) = x . environment { for ( k , v ) in env { result . insert ( k . to_string ( ) , v . to_string ( ) ) ; } } } // Override with branch context environment, // like `deploy-preview`, `branch-deploy` or `production`. if let Some ( x ) = c . get ( branch ) { if let Some ( ref env ) = x . environment { for ( k , v ) in env { result . insert ( k . to_string ( ) , v . to_string ( ) ) ; } } } } result }
Returns a HashMap that aggregates all environment variables for
a context within a git branch.
Returns a HashMap that aggregates all environment variables for a context within a git branch .
self
ctx
&str
branch
&str
example
```
let io = r#"
[build]
command = "make site"
"#.

let config = netlify_toml::from_str(io).unwrap();
let env = config.context_env("deploy-preview", "new-styles");
```
` ` ` let io = r# " [ build ] command = " make site " " # . let config = netlify_toml :: from_str ( io ) . unwrap () ; let env = config . context_env ( " deploy - preview " " new - styles " ) ; ` ` `