mirror of
https://github.com/nushell/nushell.git
synced 2025-01-01 12:00:10 +01:00
7dc1d6a350
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.
62 lines
1.2 KiB
Rust
62 lines
1.2 KiB
Rust
pub mod commands;
|
|
pub mod fs;
|
|
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()
|
|
.skip(1)
|
|
.map(|line| line.trim())
|
|
.collect::<Vec<&str>>()
|
|
.join(" ")
|
|
.trim_end()
|
|
.to_string()
|
|
}
|
|
|
|
pub fn shell_os_paths() -> Vec<std::path::PathBuf> {
|
|
let mut original_paths = vec![];
|
|
|
|
if let Some(paths) = std::env::var_os("PATH") {
|
|
original_paths = std::env::split_paths(&paths).collect::<Vec<_>>();
|
|
}
|
|
|
|
original_paths
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::pipeline;
|
|
|
|
#[test]
|
|
fn constructs_a_pipeline() {
|
|
let actual = pipeline(
|
|
r#"
|
|
open los_tres_amigos.txt
|
|
| from-csv
|
|
| get rusty_luck
|
|
| str to-int
|
|
| math sum
|
|
| echo "$it"
|
|
"#,
|
|
);
|
|
|
|
assert_eq!(
|
|
actual,
|
|
r#"open los_tres_amigos.txt | from-csv | get rusty_luck | str to-int | math sum | echo "$it""#
|
|
);
|
|
}
|
|
}
|