Fix main in scripts with captures (#4468)

* Fix main in scripts with captures

* Remove old comments
This commit is contained in:
JT
2022-02-14 10:53:48 -05:00
committed by GitHub
parent 63a2c2bc2d
commit f3d3e819fb
5 changed files with 53 additions and 104 deletions

View File

@ -2,6 +2,7 @@ use crate::is_perf_true;
use crate::utils::{eval_source, report_error};
use log::info;
use nu_protocol::engine::{EngineState, Stack, StateDelta, StateWorkingSet};
use nu_protocol::{PipelineData, Span};
use std::path::PathBuf;
const NUSHELL_FOLDER: &str = "nushell";
@ -22,8 +23,14 @@ pub(crate) fn read_plugin_file(engine_state: &mut EngineState, stack: &mut Stack
let plugin_filename = plugin_path.to_string_lossy().to_owned();
if let Ok(contents) = std::fs::read_to_string(&plugin_path) {
eval_source(engine_state, stack, &contents, &plugin_filename);
if let Ok(contents) = std::fs::read(&plugin_path) {
eval_source(
engine_state,
stack,
&contents,
&plugin_filename,
PipelineData::new(Span::new(0, 0)),
);
}
}
if is_perf_true() {
@ -49,8 +56,14 @@ pub(crate) fn read_config_file(engine_state: &mut EngineState, stack: &mut Stack
//println!("Loading config from: {:?}", config_path);
let config_filename = config_path.to_string_lossy().to_owned();
if let Ok(contents) = std::fs::read_to_string(&config_path) {
eval_source(engine_state, stack, &contents, &config_filename);
if let Ok(contents) = std::fs::read(&config_path) {
eval_source(
engine_state,
stack,
&contents,
&config_filename,
PipelineData::new(Span::new(0, 0)),
);
// Merge the delta in case env vars changed in the config
match nu_engine::env::current_dir(engine_state, stack) {
Ok(cwd) => {