nushell/crates/nu-protocol/src/engine
Douglas 72d50cf8b7
Convert Path to list in main and preserve case (#14764)
# Description

Fixes multiple issues related to `ENV_CONVERSION` and
path-conversion-to-list.

* #14681 removed some calls to `convert_env_values()`, but we found that
this caused `nu -n` to no longer convert the path properly.
* `ENV_CONVERSIONS` have apparently never preserved case, meaning a
conversion with a key of `foo` would not update `$env.FOO` but rather
create a new environment variable with a different case.
* There was a partial code-path that attempted to solve this for `PATH`,
but it only worked for `PATH` and `Path`.
* `convert_env_values()`, which handled `ENV_CONVERSIONS` was called in
multiple places in the startup depending on flags.

This PR:

* Refactors the startup to handle the conversion in `main()` rather than
in each potential startup path
* Updates `get_env_var_insensitive()` functions added in #14390 to
return the name of the environment variable with its original case. This
allows code that updates environment variables to preserve the case.
* Makes use of the updated function in `ENV_CONVERSIONS` to preserve the
case of any updated environment variables. The `ENV_CONVERSION` key
itself is still case **insensitive**.
* Makes use of the updated function to preserve the case of the `PATH`
environment variable (normally handled separately, regardless of whether
or not there was an `ENV_CONVERSION` for it).

## Before

`env_convert_values` was run:

* Before the user `env.nu` ran, which included `nu -c <commandstring>`
and `nu <script.nu>`
* Before the REPL loaded, which included `nu -n`

## After

`env_convert_values` always runs once in `main()` before any config file
is processed or the REPL is started

# User-Facing Changes

Bug fixes

# Tests + Formatting

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

Added additional tests to prevent future regression.

# After Submitting

There is additional cleanup that should probably be done in
`convert_env_values()`. This function previously handled
`ENV_CONVERSIONS`, but there is no longer any need for this since
`convert_env_vars()` runs whenever `$env.ENV_CONVERSIONS` changes now.

This means that the only relevant task in the old `convert_env_values()`
is to convert the `PATH` to a list, and ensure that it is a list of
strings. It's still calling the `from_string` conversion on every
variable (just once) even though there are no `ENV_CONVERSIONS` at this
point.

Leaving that to another PR though, while we get the core issue fixed
with this one.
2025-01-10 10:18:44 -06:00
..
argument.rs Clippy fixes for toolchain bump (#13497) 2024-07-31 14:49:22 +02:00
cached_file.rs Refactor source cache into CachedFile struct (#12240) 2024-03-20 19:43:50 +01:00
call_info.rs Add command_prelude module (#12291) 2024-03-26 21:17:30 +00:00
call.rs Replace raw usize IDs with new types (#13832) 2024-09-30 13:20:15 +02:00
capture_block.rs Remove the Value::Block case (#12582) 2024-04-21 07:03:33 +02:00
command.rs Change the usage misnomer to "description" (#13598) 2024-08-22 12:02:08 +02:00
description.rs Change the usage misnomer to "description" (#13598) 2024-08-22 12:02:08 +02:00
engine_state.rs Convert Path to list in main and preserve case (#14764) 2025-01-10 10:18:44 -06:00
error_handler.rs Clippy fixes for toolchain bump (#13497) 2024-07-31 14:49:22 +02:00
mod.rs Change the usage misnomer to "description" (#13598) 2024-08-22 12:02:08 +02:00
overlay.rs Replace raw usize IDs with new types (#13832) 2024-09-30 13:20:15 +02:00
pattern_match.rs Change how and and or operations are compiled to IR to support custom values (#14653) 2024-12-25 06:12:53 -06:00
sequence.rs feat: make ctrlc available to plugins (#13181) 2024-07-30 08:29:18 -05:00
stack_out_dest.rs Fix try printing when it is not the last pipeline element (#13992) 2024-10-12 14:37:10 +08:00
stack.rs Convert Path to list in main and preserve case (#14764) 2025-01-10 10:18:44 -06:00
state_delta.rs feat(lsp): document_symbols and workspace_symbols (#14770) 2025-01-09 07:19:32 -06:00
state_working_set.rs feat(lsp): document_symbols and workspace_symbols (#14770) 2025-01-09 07:19:32 -06:00
variable.rs Restructure nu-protocol in more meaningful units (#11917) 2024-03-10 18:45:45 +01:00