From 48b44713826c76b5748b3fda29d25631454f828c Mon Sep 17 00:00:00 2001 From: Michael Angerman <1809991+stormasm@users.noreply.github.com> Date: Mon, 6 Mar 2023 07:36:15 -0800 Subject: [PATCH] Cratification: Test Infrastructure Support Part One (#8335) startup nushell with no config file or env file... This PR gives the ability to start up nushell easily with no config or env config files simply by passing in ```rust nu -n ``` or ```rust nu --no-config-file ``` A bonus is that startup times for nushell decreases FIVE fold... From about > 50ms to less than < 10ms on average on my mac This will enable Part II which will hopefully be the ability to to send this flag into the nu! macro and turn off loading of the config files... Remember when config files are enabled the nu-cmd-lang tests fail because the commands in the config files are a superset of the commands in nu-cmd-lang... In my preliminary tests before by zeroing out the config files the nu-cmd-lang tests passed... Independent of the cratification efforts I have always wanted a way anyway to turn off loading the config files when starting up nushell... So this accomplishes that task... --- src/command.rs | 8 ++++++++ src/run.rs | 21 ++++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/command.rs b/src/command.rs index 5aab712756..7048f9e39b 100644 --- a/src/command.rs +++ b/src/command.rs @@ -101,6 +101,7 @@ pub(crate) fn parse_commandline_args( let testbin: Option = call.get_flag_expr("testbin"); #[cfg(feature = "plugin")] let plugin_file: Option = call.get_flag_expr("plugin-config"); + let no_config_file = call.get_named_arg("no-config-file"); let config_file: Option = call.get_flag_expr("config"); let env_file: Option = call.get_flag_expr("env-config"); let log_level: Option = call.get_flag_expr("log-level"); @@ -174,6 +175,7 @@ pub(crate) fn parse_commandline_args( testbin, #[cfg(feature = "plugin")] plugin_file, + no_config_file, config_file, env_file, log_level, @@ -205,6 +207,7 @@ pub(crate) struct NushellCliArgs { pub(crate) testbin: Option>, #[cfg(feature = "plugin")] pub(crate) plugin_file: Option>, + pub(crate) no_config_file: Option>, pub(crate) config_file: Option>, pub(crate) env_file: Option>, pub(crate) log_level: Option>, @@ -245,6 +248,11 @@ impl Command for Nu { "the table mode to use. rounded is default.", Some('m'), ) + .switch( + "no-config-file", + "start with no config file and no env file", + Some('n'), + ) .named( "threads", SyntaxShape::Int, diff --git a/src/run.rs b/src/run.rs index 55c2ea9db2..7aeafbff7f 100644 --- a/src/run.rs +++ b/src/run.rs @@ -201,15 +201,18 @@ pub(crate) fn run_repl( let mut stack = nu_protocol::engine::Stack::new(); let start_time = std::time::Instant::now(); - setup_config( - &mut engine_state, - &mut stack, - #[cfg(feature = "plugin")] - parsed_nu_cli_args.plugin_file, - parsed_nu_cli_args.config_file, - parsed_nu_cli_args.env_file, - parsed_nu_cli_args.login_shell.is_some(), - ); + if parsed_nu_cli_args.no_config_file.is_none() { + setup_config( + &mut engine_state, + &mut stack, + #[cfg(feature = "plugin")] + parsed_nu_cli_args.plugin_file, + parsed_nu_cli_args.config_file, + parsed_nu_cli_args.env_file, + parsed_nu_cli_args.login_shell.is_some(), + ); + } + // Reload use_color from config in case it's different from the default value let use_color = engine_state.get_config().use_ansi_coloring; perf(