-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: rules
export
shell exports (#591)
- Loading branch information
Showing
8 changed files
with
153 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use crate::nested_env; | ||
|
||
#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone)] | ||
pub struct VarExportSpec { | ||
pub variable: String, | ||
pub content: Option<String>, | ||
} | ||
|
||
impl VarExportSpec { | ||
pub fn apply_env(&self, env: &im::HashMap<&String, String>) -> Self { | ||
let content = if let Some(content) = self.content.as_ref() { | ||
content.clone() | ||
} else { | ||
format!("${{{}}}", self.variable) | ||
}; | ||
|
||
let content = | ||
Some(nested_env::expand_eval(content, env, nested_env::IfMissing::Empty).unwrap()); | ||
|
||
Self { | ||
variable: self.variable.clone(), | ||
content, | ||
} | ||
} | ||
|
||
pub(crate) fn expand( | ||
export: Option<&Vec<VarExportSpec>>, | ||
env: &im::HashMap<&String, String>, | ||
) -> Option<Vec<VarExportSpec>> { | ||
// what this does is, apply the env to the format as given by "export:" | ||
// | ||
// e.g., assuming `FOO=value` and FOOBAR=`other_value`: | ||
// ```yaml | ||
// | ||
// export: | ||
// - FOO | ||
// - BAR: bar | ||
// - FOOBAR: ${foobar} | ||
// ``` | ||
// | ||
// ... to export `FOO=value`, `BAR=bar` and `FOOBAR=other_value`. | ||
|
||
export.map(|exports| exports.iter().map(|entry| entry.apply_env(env)).collect()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters