Fix path add bug when given a record (#15379)

`path add`, when given a record, sets `$env.PATH` according to the value
of the key matching `$nu.os-info.name`. There already existed a check in
place to ensure the correct column existed, but it was never reached
because of an early error on `path expand`ing `null`. This has been
fixed, as well as the out-of-date reference to "darwin" instead of
"macos" in the example.

# User-Facing Changes

`path add` now simply ignores a record that doesn't include a key for the current OS

`path add` also will no longer add duplicate paths.
This commit is contained in:
Firegem
2025-03-22 08:42:20 -04:00
committed by GitHub
parent 7c160725ed
commit f33a26123c
3 changed files with 39 additions and 25 deletions

View File

@ -39,6 +39,12 @@ def path_add [] {
path add $target_paths
assert equal (get_path) ([($target_paths | get $nu.os-info.name)] | path expand)
load-env {$path_name: []}
path add {}
assert equal (get_path) []
assert error {|| path add 1 }
load-env {$path_name: [$"(["/foo", "/bar"] | path expand | str join (char esep))"]}
path add "~/foo"
assert equal (get_path) (["~/foo", "/foo", "/bar"] | path expand)

View File

@ -39,6 +39,12 @@ def path_add [] {
path add $target_paths
assert equal (get_path) ([($target_paths | get $nu.os-info.name)] | path expand)
load-env {$path_name: []}
path add {}
assert equal (get_path) ([])
assert error {|| path add 1 }
load-env {$path_name: [$"(["/foo", "/bar"] | path expand | str join (char esep))"]}
path add "~/foo"
assert equal (get_path) (["~/foo", "/foo", "/bar"] | path expand)