mirror of
https://github.com/nushell/nushell.git
synced 2025-08-21 13:50:37 +02:00
Make $nu constant (#10160)
This commit is contained in:
10
src/main.rs
10
src/main.rs
@@ -24,8 +24,10 @@ use log::Level;
|
||||
use miette::Result;
|
||||
use nu_cli::gather_parent_env_vars;
|
||||
use nu_cmd_base::util::get_init_cwd;
|
||||
use nu_protocol::{engine::EngineState, report_error_new, Value};
|
||||
use nu_protocol::{util::BufferedReader, PipelineData, RawStream};
|
||||
use nu_protocol::{
|
||||
engine::EngineState, eval_const::create_nu_constant, report_error_new, util::BufferedReader,
|
||||
PipelineData, RawStream, Span, Value, NU_VARIABLE_ID,
|
||||
};
|
||||
use nu_std::load_standard_library;
|
||||
use nu_utils::utils::perf;
|
||||
use run::{run_commands, run_file, run_repl};
|
||||
@@ -274,6 +276,10 @@ fn main() -> Result<()> {
|
||||
use_color,
|
||||
);
|
||||
|
||||
// Set up the $nu constant before evaluating config files (need to have $nu available in them)
|
||||
let nu_const = create_nu_constant(&engine_state, input.span().unwrap_or_else(Span::unknown))?;
|
||||
engine_state.set_variable_const_val(NU_VARIABLE_ID, nu_const);
|
||||
|
||||
if let Some(commands) = parsed_nu_cli_args.commands.clone() {
|
||||
run_commands(
|
||||
&mut engine_state,
|
||||
|
13
src/run.rs
13
src/run.rs
@@ -7,7 +7,8 @@ use crate::{
|
||||
#[cfg(feature = "plugin")]
|
||||
use nu_cli::read_plugin_file;
|
||||
use nu_cli::{evaluate_commands, evaluate_file, evaluate_repl};
|
||||
use nu_protocol::PipelineData;
|
||||
use nu_protocol::eval_const::create_nu_constant;
|
||||
use nu_protocol::{PipelineData, Span, NU_VARIABLE_ID};
|
||||
use nu_utils::utils::perf;
|
||||
|
||||
pub(crate) fn run_commands(
|
||||
@@ -82,8 +83,14 @@ pub(crate) fn run_commands(
|
||||
use_color,
|
||||
);
|
||||
}
|
||||
|
||||
// Before running commands, set up the startup time
|
||||
engine_state.set_startup_time(entire_start_time.elapsed().as_nanos() as i64);
|
||||
|
||||
// Regenerate the $nu constant to contain the startup time and any other potential updates
|
||||
let nu_const = create_nu_constant(engine_state, commands.span)?;
|
||||
engine_state.set_variable_const_val(NU_VARIABLE_ID, nu_const);
|
||||
|
||||
let start_time = std::time::Instant::now();
|
||||
let ret_val = evaluate_commands(
|
||||
commands,
|
||||
@@ -169,6 +176,10 @@ pub(crate) fn run_file(
|
||||
use_color,
|
||||
);
|
||||
|
||||
// Regenerate the $nu constant to contain the startup time and any other potential updates
|
||||
let nu_const = create_nu_constant(engine_state, input.span().unwrap_or_else(Span::unknown))?;
|
||||
engine_state.set_variable_const_val(NU_VARIABLE_ID, nu_const);
|
||||
|
||||
let start_time = std::time::Instant::now();
|
||||
let ret_val = evaluate_file(
|
||||
script_name,
|
||||
|
Reference in New Issue
Block a user