mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 14:40:06 +02:00
Add Nushell REPL simulator; Fix bug in overlay add (#5478)
* Add Nushell REPL simulator; Fix bug in overlay add The `nu_repl` function takes an array of strings and processes them as if they were REPL lines entered one by one. This helps to discover bugs due to the state changes between the parse and eval stages. * Fix REPL tests on Windows
This commit is contained in:
@ -211,8 +211,8 @@ pub fn eval_source(
|
||||
(output, working_set.render())
|
||||
};
|
||||
|
||||
let cwd = match nu_engine::env::current_dir_str(engine_state, stack) {
|
||||
Ok(p) => PathBuf::from(p),
|
||||
let cwd = match nu_engine::env::current_dir(engine_state, stack) {
|
||||
Ok(p) => p,
|
||||
Err(e) => {
|
||||
let working_set = StateWorkingSet::new(engine_state);
|
||||
report_error(&working_set, &e);
|
||||
|
@ -53,8 +53,46 @@ https://www.nushell.sh/book/thinking_in_nushell.html#parsing-and-evaluation-are-
|
||||
|
||||
// TODO: This logic is duplicated in the parser.
|
||||
if stack.has_env_overlay(&name_arg.item, engine_state) {
|
||||
stack.add_overlay(name_arg.item);
|
||||
// Activate existing overlay
|
||||
stack.add_overlay(name_arg.item.clone());
|
||||
|
||||
if let Some(module_id) = engine_state
|
||||
.find_overlay(name_arg.item.as_bytes())
|
||||
.map(|id| engine_state.get_overlay(id).origin)
|
||||
{
|
||||
if let Some(new_module_id) = engine_state.find_module(name_arg.item.as_bytes(), &[])
|
||||
{
|
||||
if module_id != new_module_id {
|
||||
// The origin module of an overlay changed => update it
|
||||
let module = engine_state.get_module(new_module_id);
|
||||
|
||||
for (name, block_id) in module.env_vars() {
|
||||
let name = if let Ok(s) = String::from_utf8(name.clone()) {
|
||||
s
|
||||
} else {
|
||||
return Err(ShellError::NonUtf8(name_arg.span));
|
||||
};
|
||||
|
||||
let block = engine_state.get_block(block_id);
|
||||
|
||||
let val = eval_block(
|
||||
engine_state,
|
||||
stack,
|
||||
block,
|
||||
PipelineData::new(call.head),
|
||||
false,
|
||||
true,
|
||||
)?
|
||||
.into_value(call.head);
|
||||
|
||||
stack.add_env_var(name, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
} else {
|
||||
// Create a new overlay from a module
|
||||
let (overlay_name, module) =
|
||||
if let Some(module_id) = engine_state.find_module(name_arg.item.as_bytes(), &[]) {
|
||||
(name_arg.item, engine_state.get_module(module_id))
|
||||
|
Reference in New Issue
Block a user