From 1de57eb2b6d1f04d28ccf19b92525cce0bf04829 Mon Sep 17 00:00:00 2001 From: Mel Massadian Date: Thu, 18 May 2023 01:55:46 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20handle=20windows=20Path?= =?UTF-8?q?=20casing=20(#9210)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description PATH and Path are different (in nushell at least) based on the OS # User-Facing Changes None the command now works as expected # Tests + Formatting # After Submitting --- crates/nu-std/lib/mod.nu | 15 +++++++++------ crates/nu-std/tests/test_std.nu | 18 +++++++++++------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/crates/nu-std/lib/mod.nu b/crates/nu-std/lib/mod.nu index 42b0364389..b262e99af8 100644 --- a/crates/nu-std/lib/mod.nu +++ b/crates/nu-std/lib/mod.nu @@ -38,14 +38,17 @@ export def-env "path add" [ --append (-a) # append to $env.PATH instead of prepending to. ...paths # the paths to add to $env.PATH. ] { - let-env PATH = ( - $env.PATH - | if $append { append $paths } - else { prepend $paths } - ) + let path_name = if "PATH" in $env { "PATH" } else { "Path" } + let-env $path_name = ( + $env + | get $path_name + | if $append { append $paths } + else { prepend $paths } + ) + if $ret { - $env.PATH + $env | get $path_name } } diff --git a/crates/nu-std/tests/test_std.nu b/crates/nu-std/tests/test_std.nu index fe5b8e7334..9a7c1452f4 100644 --- a/crates/nu-std/tests/test_std.nu +++ b/crates/nu-std/tests/test_std.nu @@ -3,23 +3,27 @@ use std export def test_path_add [] { use std "assert equal" - with-env [PATH []] { - assert equal $env.PATH [] + let path_name = if "PATH" in $env { "PATH" } else { "Path" } + + with-env [$path_name []] { + def get_path [] { $env | get $path_name } + + assert equal (get_path) [] std path add "/foo/" - assert equal $env.PATH ["/foo/"] + assert equal (get_path) ["/foo/"] std path add "/bar/" "/baz/" - assert equal $env.PATH ["/bar/", "/baz/", "/foo/"] + assert equal (get_path) ["/bar/", "/baz/", "/foo/"] - let-env PATH = [] + let-env $path_name = [] std path add "foo" std path add "bar" "baz" --append - assert equal $env.PATH ["foo", "bar", "baz"] + assert equal (get_path) ["foo", "bar", "baz"] assert equal (std path add "fooooo" --ret) ["fooooo", "foo", "bar", "baz"] - assert equal $env.PATH ["fooooo", "foo", "bar", "baz"] + assert equal (get_path) ["fooooo", "foo", "bar", "baz"] } }