mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 21:37:54 +02:00
Update config directly at assignment (#13332)
# Description Allows `Stack` to have a modified local `Config`, which is updated immediately when `$env.config` is assigned to. This means that even within a script, commands that come after `$env.config` changes will always see those changes in `Stack::get_config()`. Also fixed a lot of cases where `engine_state.get_config()` was used even when `Stack` was available. Closes #13324. # User-Facing Changes - Config changes apply immediately after the assignment is executed, rather than whenever config is read by a command that needs it. - Potentially slower performance when executing a lot of lines that change `$env.config` one after another. Recommended to get `$env.config` into a `mut` variable first and do modifications, then assign it back. - Much faster performance when executing a script that made modifications to `$env.config`, as the changes are only parsed once. # Tests + Formatting All passing. # After Submitting - [ ] release notes
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
use nu_engine::command_prelude::*;
|
||||
use nu_protocol::Config;
|
||||
use url::Url;
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -38,11 +39,15 @@ impl Command for SubCommand {
|
||||
fn run(
|
||||
&self,
|
||||
engine_state: &EngineState,
|
||||
_: &mut Stack,
|
||||
stack: &mut Stack,
|
||||
call: &Call,
|
||||
input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
parse(input.into_value(call.head)?, call.head, engine_state)
|
||||
parse(
|
||||
input.into_value(call.head)?,
|
||||
call.head,
|
||||
&stack.get_config(engine_state),
|
||||
)
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
@ -68,12 +73,12 @@ impl Command for SubCommand {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_url_string(value: &Value, engine_state: &EngineState) -> String {
|
||||
value.to_expanded_string("", engine_state.get_config())
|
||||
fn get_url_string(value: &Value, config: &Config) -> String {
|
||||
value.to_expanded_string("", config)
|
||||
}
|
||||
|
||||
fn parse(value: Value, head: Span, engine_state: &EngineState) -> Result<PipelineData, ShellError> {
|
||||
let url_string = get_url_string(&value, engine_state);
|
||||
fn parse(value: Value, head: Span, config: &Config) -> Result<PipelineData, ShellError> {
|
||||
let url_string = get_url_string(&value, config);
|
||||
|
||||
let result_url = Url::parse(url_string.as_str());
|
||||
|
||||
|
Reference in New Issue
Block a user