mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 22:50:14 +02:00
Extract .nu-env tests and more granularity (#3078)
The autoenv logic mutates environment variables in the running session as it operates and decides what to do for trusted directories containing `.nu-env` files. Few of the ways to interact with it were all in a single test function. We separate out all the ways that were done in the single test function to document it better. This will greatly help once we start refactoring our way out from setting environment variables this way to just setting them to `Scope`. This is part of an on-going effort to keep variables (`PATH` and `ENV`) in our `Scope` and rely on it for everything related to variables. We expect to move away from setting (`std::*`) envrironment variables in the current running process. This is non-trivial since we need to handle cases from vars coming in from the outside world, prioritize, and also compare to the ones we have both stored in memory and in configuration files. Also to send out our in-memory (in `Scope`) variables properly to external programs once we no longer rely on `std::env` vars from the running process.
This commit is contained in:
committed by
GitHub
parent
deff1aa63b
commit
7dc1d6a350
@ -25,6 +25,7 @@ pub fn file_is_trusted(nu_env_file: &Path, content: &[u8]) -> Result<bool, Shell
|
||||
let nufile = std::fs::canonicalize(nu_env_file)?;
|
||||
|
||||
let trusted = read_trusted()?;
|
||||
|
||||
Ok(trusted.files.get(&nufile.to_string_lossy().to_string()) == Some(&contentdigest))
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,17 @@ pub mod macros;
|
||||
pub mod playground;
|
||||
pub mod value;
|
||||
|
||||
pub struct Outcome {
|
||||
pub out: String,
|
||||
pub err: String,
|
||||
}
|
||||
|
||||
impl Outcome {
|
||||
pub fn new(out: String, err: String) -> Outcome {
|
||||
Outcome { out, err }
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pipeline(commands: &str) -> String {
|
||||
commands
|
||||
.lines()
|
||||
|
@ -71,7 +71,7 @@ macro_rules! nu {
|
||||
|
||||
println!("=== stderr\n{}", err);
|
||||
|
||||
$crate::macros::Outcome::new(out,err.into_owned())
|
||||
$crate::Outcome::new(out,err.into_owned())
|
||||
}};
|
||||
}
|
||||
|
||||
@ -147,21 +147,10 @@ macro_rules! nu_with_plugins {
|
||||
|
||||
println!("=== stderr\n{}", err);
|
||||
|
||||
$crate::macros::Outcome::new(out,err.into_owned())
|
||||
$crate::Outcome::new(out,err.into_owned())
|
||||
}};
|
||||
}
|
||||
|
||||
pub struct Outcome {
|
||||
pub out: String,
|
||||
pub err: String,
|
||||
}
|
||||
|
||||
impl Outcome {
|
||||
pub fn new(out: String, err: String) -> Outcome {
|
||||
Outcome { out, err }
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_std(std: &[u8]) -> String {
|
||||
let out = String::from_utf8_lossy(std);
|
||||
let out = out.lines().skip(1).collect::<Vec<_>>().join("\n");
|
||||
|
Reference in New Issue
Block a user