From ffde939df3478c190a4dd964cfc6f1b7231e4ee2 Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Thu, 25 May 2023 08:24:56 -0500 Subject: [PATCH] if --no-config-file(-n) is passed, do not load config files with -c (#9286) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description I noticed recently these timing discrepancies. I was thinking they would be nearly identical but they were not. ``` > nu --no-std-lib -n -c "$nu.startup-time" 13ms 686µs 209ns > nu --no-std-lib -n > $nu.startup-time 2ms 520µs 416ns ``` My research showed that if `-n` was passed with `-c`, then the `-n` was essentially being ignored. This PR corrects that. Also worthy of understanding, if `nu -c "some command"` is passed, the default env file is always loaded. I believe that's on purpose so that a NU_LIB_DIRS env is available. ## After this PR (on a different system) ``` > nu --no-std-lib -n -c "$nu.startup-time" 6ms 688µs 600ns > nu -n --no-std-lib > $nu.startup-time 6ms 661µs 800ns ``` # User-Facing Changes # Tests + Formatting # After Submitting --- src/run.rs | 103 +++++++++++++++++++++++++++++------------------------ 1 file changed, 57 insertions(+), 46 deletions(-) diff --git a/src/run.rs b/src/run.rs index 3a22c0bc90..cea9109860 100644 --- a/src/run.rs +++ b/src/run.rs @@ -21,56 +21,67 @@ pub(crate) fn run_commands( let mut stack = nu_protocol::engine::Stack::new(); let start_time = std::time::Instant::now(); - #[cfg(feature = "plugin")] - read_plugin_file( - engine_state, - &mut stack, - parsed_nu_cli_args.plugin_file, - NUSHELL_FOLDER, - ); - perf( - "read plugins", - start_time, - file!(), - line!(), - column!(), - use_color, - ); - - let start_time = std::time::Instant::now(); - // only want to load config and env if relative argument is provided. - if parsed_nu_cli_args.env_file.is_some() { - config_files::read_config_file(engine_state, &mut stack, parsed_nu_cli_args.env_file, true); - } else { - config_files::read_default_env_file(engine_state, &mut stack) - } - perf( - "read env.nu", - start_time, - file!(), - line!(), - column!(), - use_color, - ); - - let start_time = std::time::Instant::now(); - if parsed_nu_cli_args.config_file.is_some() { - config_files::read_config_file( + // if the --no-config-file(-n) option is NOT passed, load the plugin file, + // load the default env file or custom (depending on parsed_nu_cli_args.env_file), + // and maybe a custom config file (depending on parsed_nu_cli_args.config_file) + // + // if the --no-config-file(-n) flag is passed, do not load plugin, env, or config files + if parsed_nu_cli_args.no_config_file.is_none() { + #[cfg(feature = "plugin")] + read_plugin_file( engine_state, &mut stack, - parsed_nu_cli_args.config_file, - false, + parsed_nu_cli_args.plugin_file, + NUSHELL_FOLDER, + ); + perf( + "read plugins", + start_time, + file!(), + line!(), + column!(), + use_color, + ); + + let start_time = std::time::Instant::now(); + // only want to load config and env if relative argument is provided. + if parsed_nu_cli_args.env_file.is_some() { + config_files::read_config_file( + engine_state, + &mut stack, + parsed_nu_cli_args.env_file, + true, + ); + } else { + config_files::read_default_env_file(engine_state, &mut stack) + } + perf( + "read env.nu", + start_time, + file!(), + line!(), + column!(), + use_color, + ); + + let start_time = std::time::Instant::now(); + if parsed_nu_cli_args.config_file.is_some() { + config_files::read_config_file( + engine_state, + &mut stack, + parsed_nu_cli_args.config_file, + false, + ); + } + perf( + "read config.nu", + start_time, + file!(), + line!(), + column!(), + use_color, ); } - perf( - "read config.nu", - start_time, - file!(), - line!(), - column!(), - use_color, - ); - // Before running commands, set up the startup time engine_state.set_startup_time(entire_start_time.elapsed().as_nanos() as i64); let start_time = std::time::Instant::now();