Skip to content

Commit

Permalink
add path replace-extension to stdlib-candidate (#1002)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
WindSoilder authored Jan 4, 2025
1 parent 66e4845 commit 2dadab7
Show file tree
Hide file tree
Showing 5 changed files with 445 additions and 3 deletions.
2 changes: 1 addition & 1 deletion stdlib-candidate/nupm.nuon
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
description: "Official candidates for Nushell standard library"
documentation: "https://github.com/nushell/nu_scripts/blob/main/stdlib-candidate/std-rfc/README.md"
license: "https://github.com/nushell/nu_scripts/blob/main/LICENSE"
version: 0.4.0
version: 0.4.1
type: "module"
}
30 changes: 30 additions & 0 deletions stdlib-candidate/path/mod.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Replace extension of input file paths.
#
# Note that it doesn't change the file name locally.
#
# # Example
# - setting path ext to `rs`
# ```nushell
# > "ab.txt" | path replace-extension "rs"
# ab.rs
# > "ab.txt" | path replace-extension ".rs"
# ab.rs
#
# - setting a list of input path ext to `rs`
# > ["ab.txt", "cd.exe"] | path replace-extension "rs"
# ╭───┬──────────╮
# │ 0 │ ab.rs │
# │ 1 │ cd.rs │
# ╰───┴──────────╯
# ```
export def replace-extension [
ext: string
] {
let path_parsed = $in | path parse
if ($ext | str starts-with ".") {
$path_parsed | update extension ($ext | str substring 1..) | path join
} else {
$path_parsed | update extension $ext | path join
}
}

Loading

0 comments on commit 2dadab7

Please sign in to comment.