b66a979c08
Add a setting that exports all variables by default, regardless of whether they use the `export` keyword. This includes assignments as well as parameters. Just does dependency analysis of variable uses, allowing variables to be used out of order in assignments, as long as there are no circular dependencies. However, use of environment variable is not known to Just, so exported variables are only exported to child scopes, to avoid ordering dependencies, since dependency analysis cannot be done.
32 lines
831 B
Rust
32 lines
831 B
Rust
use crate::common::*;
|
|
|
|
pub(crate) trait CommandExt {
|
|
fn export(&mut self, settings: &Settings, dotenv: &BTreeMap<String, String>, scope: &Scope);
|
|
|
|
fn export_scope(&mut self, settings: &Settings, scope: &Scope);
|
|
}
|
|
|
|
impl CommandExt for Command {
|
|
fn export(&mut self, settings: &Settings, dotenv: &BTreeMap<String, String>, scope: &Scope) {
|
|
for (name, value) in dotenv {
|
|
self.env(name, value);
|
|
}
|
|
|
|
if let Some(parent) = scope.parent() {
|
|
self.export_scope(settings, parent);
|
|
}
|
|
}
|
|
|
|
fn export_scope(&mut self, settings: &Settings, scope: &Scope) {
|
|
if let Some(parent) = scope.parent() {
|
|
self.export_scope(settings, parent);
|
|
}
|
|
|
|
for binding in scope.bindings() {
|
|
if settings.export || binding.export {
|
|
self.env(binding.name.lexeme(), &binding.value);
|
|
}
|
|
}
|
|
}
|
|
}
|