Skip to content

Commit

Permalink
Pass full path as explicit closure param
Browse files Browse the repository at this point in the history
  • Loading branch information
texastoland committed Mar 22, 2024
1 parent 743311b commit 7b0e5b9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
5 changes: 4 additions & 1 deletion stdlib-candidate/std-rfc/batch-rename.nu
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ export def main [
error make { msg: 'batch-rename expects input paths or a valid --directory' }
}
$paths | par-each { |old|
let update_stem = { do $update_stem { stem: $in full: $old } }
let new = $old | path parse | update stem $update_stem | path join
mv --force --verbose=$verbose $old $new
if $new != $old {
mv --force --verbose=$verbose $old $new
}
}
ignore
}
19 changes: 18 additions & 1 deletion stdlib-candidate/tests/batch-rename.nu
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ export def 'test batch-rename --directory' [] {
] { batch-rename --directory $in { '_' + $in } }
}

export def 'test batch-rename skip-extensions' [] {
test --expects [
.gitignore
Cargo.toml
LICENSE.txt
README.md
src.txt
test.nu
] { batch-rename --directory $in { |path|
if $path.full ends-with $path.stem {
$path.stem + .txt
} else {
$path.stem
}
} }
}

export def 'test batch-rename glob' [] {
test --expects [
LICENSE # skip
Expand All @@ -32,7 +49,7 @@ export def 'test batch-rename glob' [] {
] { glob ($in | path join *.*) | batch-rename { '_' + $in } }
}

export def 'test batch-rename missing args' [] {
export def 'test batch-rename missing-args' [] {
assert error {
test { ignore | batch-rename { '_' + $in } }
}
Expand Down

0 comments on commit 7b0e5b9

Please sign in to comment.