Skip to content

Commit 2dadab7

Browse files
authored
add path replace-extension to stdlib-candidate (#1002)
Adds `path replace-extension` as requested in nushell/nushell#14144 Also sets up testing for candidates. In order to do this, I made some changes: 1. ported `nu-std/testing.nu` under `stdlib-candidate` folder, and making some changes. 2. run candidate tests in `toolkit check pr` command, to make sure the test is run in CI. 3. including `stdlib-candidate` to `NU_LIB_DIRS` when running lint, so the tests can pass linter. Changes in stdlib-candidate/testing.nu: 1. remove `std/log` usage 2. including `stdlib-candidate` path in `run-test` command
1 parent 66e4845 commit 2dadab7

File tree

5 files changed

+445
-3
lines changed

5 files changed

+445
-3
lines changed

stdlib-candidate/nupm.nuon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
description: "Official candidates for Nushell standard library"
44
documentation: "https://github.com/nushell/nu_scripts/blob/main/stdlib-candidate/std-rfc/README.md"
55
license: "https://github.com/nushell/nu_scripts/blob/main/LICENSE"
6-
version: 0.4.0
6+
version: 0.4.1
77
type: "module"
88
}

stdlib-candidate/path/mod.nu

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Replace extension of input file paths.
2+
#
3+
# Note that it doesn't change the file name locally.
4+
#
5+
# # Example
6+
# - setting path ext to `rs`
7+
# ```nushell
8+
# > "ab.txt" | path replace-extension "rs"
9+
# ab.rs
10+
# > "ab.txt" | path replace-extension ".rs"
11+
# ab.rs
12+
#
13+
# - setting a list of input path ext to `rs`
14+
# > ["ab.txt", "cd.exe"] | path replace-extension "rs"
15+
# ╭───┬──────────╮
16+
# │ 0 │ ab.rs │
17+
# │ 1 │ cd.rs │
18+
# ╰───┴──────────╯
19+
# ```
20+
export def replace-extension [
21+
ext: string
22+
] {
23+
let path_parsed = $in | path parse
24+
if ($ext | str starts-with ".") {
25+
$path_parsed | update extension ($ext | str substring 1..) | path join
26+
} else {
27+
$path_parsed | update extension $ext | path join
28+
}
29+
}
30+

0 commit comments

Comments
 (0)