mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 08:55:40 +02:00
Merge stack before printing (#9304)
Could you @fdncred try it? close?: #9264 --------- Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com> Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
This commit is contained in:
@ -279,11 +279,7 @@ impl EngineState {
|
||||
}
|
||||
|
||||
/// Merge the environment from the runtime Stack into the engine state
|
||||
pub fn merge_env(
|
||||
&mut self,
|
||||
stack: &mut Stack,
|
||||
cwd: impl AsRef<Path>,
|
||||
) -> Result<(), ShellError> {
|
||||
pub fn merge_env(&mut self, stack: &mut Stack) -> Result<(), ShellError> {
|
||||
for mut scope in stack.env_vars.drain(..) {
|
||||
for (overlay_name, mut env) in scope.drain() {
|
||||
if let Some(env_vars) = self.env_vars.get_mut(&overlay_name) {
|
||||
@ -310,12 +306,27 @@ impl EngineState {
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Set a CWD.
|
||||
pub fn set_current_working_dir(&mut self, cwd: impl AsRef<Path>) -> Result<(), ShellError> {
|
||||
// TODO: better error
|
||||
std::env::set_current_dir(cwd)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Merge the environment from the runtime Stack into the engine state
|
||||
///
|
||||
/// A merge which does not consume the stack env.
|
||||
pub fn clone_with_env(&self, stack: &Stack) -> Result<Self, ShellError> {
|
||||
let mut engine = self.clone();
|
||||
let mut stack = stack.clone();
|
||||
engine.merge_env(&mut stack)?;
|
||||
|
||||
Ok(engine)
|
||||
}
|
||||
|
||||
/// Mark a starting point if it is a script (e.g., nu spam.nu)
|
||||
pub fn start_in_file(&mut self, file_path: Option<&str>) {
|
||||
self.currently_parsed_cwd = if let Some(path) = file_path {
|
||||
|
Reference in New Issue
Block a user