-
Notifications
You must be signed in to change notification settings - Fork 521
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up scope handling by introducing `Binding` and `Scope` objects.
- Loading branch information
Showing
21 changed files
with
543 additions
and
438 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,4 @@ | ||
use crate::common::*; | ||
|
||
/// An assignment, e.g `foo := bar` | ||
#[derive(Debug, PartialEq)] | ||
pub(crate) struct Assignment<'src> { | ||
/// Assignment was prefixed by the `export` keyword | ||
pub(crate) export: bool, | ||
/// Left-hand side of the assignment | ||
pub(crate) name: Name<'src>, | ||
/// Right-hand side of the assignment | ||
pub(crate) expression: Expression<'src>, | ||
} | ||
|
||
impl<'src> Keyed<'src> for Assignment<'src> { | ||
fn key(&self) -> &'src str { | ||
self.name.lexeme() | ||
} | ||
} | ||
pub(crate) type Assignment<'src> = Binding<'src, Expression<'src>>; |
This file was deleted.
Oops, something went wrong.
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,18 @@ | ||
use crate::common::*; | ||
|
||
/// A binding of `name` to `value` | ||
#[derive(Debug, PartialEq)] | ||
pub(crate) struct Binding<'src, V = String> { | ||
/// Export binding as an environment variable to child processes | ||
pub(crate) export: bool, | ||
/// Binding name | ||
pub(crate) name: Name<'src>, | ||
/// Binding value | ||
pub(crate) value: V, | ||
} | ||
|
||
impl<'src, V> Keyed<'src> for Binding<'src, V> { | ||
fn key(&self) -> &'src str { | ||
self.name.lexeme() | ||
} | ||
} |
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 |
---|---|---|
@@ -1,29 +1,31 @@ | ||
use crate::common::*; | ||
|
||
pub(crate) trait CommandExt { | ||
fn export_environment_variables<'a>( | ||
&mut self, | ||
scope: &BTreeMap<&'a str, (bool, String)>, | ||
dotenv: &BTreeMap<String, String>, | ||
) -> RunResult<'a, ()>; | ||
fn export(&mut self, dotenv: &BTreeMap<String, String>, scope: &Scope); | ||
|
||
fn export_scope(&mut self, scope: &Scope); | ||
} | ||
|
||
impl CommandExt for Command { | ||
fn export_environment_variables<'a>( | ||
&mut self, | ||
scope: &BTreeMap<&'a str, (bool, String)>, | ||
dotenv: &BTreeMap<String, String>, | ||
) -> RunResult<'a, ()> { | ||
fn export(&mut self, dotenv: &BTreeMap<String, String>, scope: &Scope) { | ||
for (name, value) in dotenv { | ||
self.env(name, value); | ||
} | ||
|
||
for (name, (export, value)) in scope { | ||
if *export { | ||
self.env(name, value); | ||
} | ||
if let Some(parent) = scope.parent() { | ||
self.export_scope(parent); | ||
} | ||
} | ||
|
||
Ok(()) | ||
fn export_scope(&mut self, scope: &Scope) { | ||
if let Some(parent) = scope.parent() { | ||
self.export_scope(parent); | ||
} | ||
|
||
for binding in scope.bindings() { | ||
if binding.export { | ||
self.env(binding.name.lexeme(), &binding.value); | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.