pub(crate) fn evaluate(
    path: String,
    args: &[String],
    engine_state: &mut EngineState,
    input: PipelineData,
) -> Result<()> {
    // First, set up env vars as strings only
    gather_parent_env_vars(engine_state);

    let mut stack = nu_protocol::engine::Stack::new();

    // Set up our initial config to start from
    stack.vars.insert(
        CONFIG_VARIABLE_ID,
        Value::Record {
            cols: vec![],
            vals: vec![],
            span: Span { start: 0, end: 0 },
        },
    );

    // Translate environment variables from Strings to Values
    if let Some(e) = convert_env_values(engine_state, &stack) {
        let working_set = StateWorkingSet::new(engine_state);
        report_error(&working_set, &e);
        std::process::exit(1);
    }

    let file = std::fs::read(&path).into_diagnostic()?;

    let mut working_set = StateWorkingSet::new(engine_state);
    trace!("parsing file: {}", path);

    let _ = parse(&mut working_set, Some(&path), &file, false);

    if working_set.find_decl(b"main").is_some() {
        let args = format!("main {}", args.join(" "));

        eval_source(
            engine_state,
            &mut stack,
            &file,
            &path,
            PipelineData::new(Span::new(0, 0)),
        );
        eval_source(
            engine_state,
            &mut stack,
            args.as_bytes(),
            "<commandline>",
            input,
        );
    } else {
        eval_source(engine_state, &mut stack, &file, &path, input);
    }

    if is_perf_true() {
        info!("evaluate {}:{}:{}", file!(), line!(), column!());
    }

    Ok(())
}
/// Main function used when a file path is found as argument for nu
Main function used when a file path is found as argument for nu
Main function used when a file path is found as argument for nu
pub(crate) fn evaluate(
    path: String,
    args: &[String],
    engine_state: &mut EngineState,
    input: PipelineData,
) -> Result<()> {
    // First, set up env vars as strings only
    gather_parent_env_vars(engine_state);
    let mut stack = nu_protocol::engine::Stack::new();
    // Set up our initial config to start from
    stack.vars.insert(
        CONFIG_VARIABLE_ID,
        Value::Record {
            cols: vec![],
            vals: vec![],
            span: Span { start: 0, end: 0 },
        },
    );
    // Translate environment variables from Strings to Values
    if let Some(e) = convert_env_values(engine_state, &stack) {
        let working_set = StateWorkingSet::new(engine_state);
        report_error(&working_set, &e);
        std::process::exit(1);
    }
    let file = std::fs::read(&path).into_diagnostic()?;
    let mut working_set = StateWorkingSet::new(engine_state);
    trace!("parsing file: {}", path);
    let _ = parse(&mut working_set, Some(&path), &file, false);
    if working_set.find_decl(b"main").is_some() {
        let args = format!("main {}", args.join(" "));
        eval_source(
            engine_state,
            &mut stack,
            &file,
            &path,
            PipelineData::new(Span::new(0, 0)),
        );
        eval_source(
            engine_state,
            &mut stack,
            args.as_bytes(),
            "<commandline>",
            input,
        );
    } else {
        eval_source(engine_state, &mut stack, &file, &path, input);
    }
    if is_perf_true() {
        info!("evaluate {}:{}:{}", file!(), line!(), column!());
    }
    Ok(())
}
pub ( crate ) fn evaluate ( path : String , args : & [ String ] , engine_state : & mut EngineState , input : PipelineData , ) -> Result < ( ) > { // First, set up env vars as strings only gather_parent_env_vars ( engine_state ) ; let mut stack = nu_protocol :: engine :: Stack :: new ( ) ; // Set up our initial config to start from stack . vars . insert ( CONFIG_VARIABLE_ID , Value :: Record { cols : vec ! [ ] , vals : vec ! [ ] , span : Span { start : 0 , end : 0 } , } , ) ; // Translate environment variables from Strings to Values if let Some ( e ) = convert_env_values ( engine_state , & stack ) { let working_set = StateWorkingSet :: new ( engine_state ) ; report_error ( & working_set , & e ) ; std :: process :: exit ( 1 ) ; } let file = std :: fs :: read ( & path ) . into_diagnostic ( ) ? ; let mut working_set = StateWorkingSet :: new ( engine_state ) ; trace ! ( " " path ) ; let _ = parse ( & mut working_set , Some ( & path ) , & file , false ) ; if working_set . find_decl ( b" " ) . is_some ( ) { let args = format ! ( " " args join ( " " ) ) ; eval_source ( engine_state , & mut stack , & file , & path , PipelineData :: new ( Span :: new ( 0 , 0 ) ) , ) ; eval_source ( engine_state , & mut stack , args . as_bytes ( ) , " " , input , ) ; } else { eval_source ( engine_state , & mut stack , & file , & path , input ) ; } if is_perf_true ( ) { info ! ( " " file ( ) line ( ) column ( ) ) ; } Ok ( ( ) ) }
Main function used when a file path is found as argument for nu
Main function used when a file path is found as argument for nu
path
String
args
&[String]
engine_state
&mut EngineState
input
PipelineData
path
String
args
&[String]
engine_state
&mut EngineState
input
PipelineData