forked from extern/nushell
docs(std-rfc): use actual examples rather than doc comments (#15097)
# Description Update examples with attributes. # User-Facing Changes `std-rfc` commands now have examples. # Tests + Formatting N/A # After Submitting N/A
This commit is contained in:
@ -5,25 +5,20 @@ def with-field [field: string, value: string] {
|
||||
| path join
|
||||
}
|
||||
|
||||
alias "path with-extension" = with-extension
|
||||
|
||||
# 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 with-extension "rs"
|
||||
# ab.rs
|
||||
# > "ab.txt" | path with-extension ".rs"
|
||||
# ab.rs
|
||||
#
|
||||
# - setting a list of input path ext to `rs`
|
||||
# > ["ab.txt", "cd.exe"] | path with-extension "rs"
|
||||
# ╭───┬──────────╮
|
||||
# │ 0 │ ab.rs │
|
||||
# │ 1 │ cd.rs │
|
||||
# ╰───┴──────────╯
|
||||
# ```
|
||||
@example "setting path ext to `rs`" {
|
||||
"ab.txt" | path with-extension "rs"
|
||||
} --result ab.rs
|
||||
@example "leading dot can be included" {
|
||||
"ab.txt" | path with-extension ".rs"
|
||||
} --result ab.rs
|
||||
@example "setting a list of input path ext to `rs`" {
|
||||
["ab.txt", "cd.exe"] | path with-extension "rs"
|
||||
} --result [ab.rs, cd.rs]
|
||||
export def with-extension [ext: string] {
|
||||
let path = $in
|
||||
let ext_trim = if $ext starts-with "." {
|
||||
@ -34,38 +29,26 @@ export def with-extension [ext: string] {
|
||||
$path | with-field extension $ext_trim
|
||||
}
|
||||
|
||||
alias "path with-stem" = with-stem
|
||||
|
||||
# Replace stem of input file paths.
|
||||
#
|
||||
# Note that it doesn't change the file name locally.
|
||||
#
|
||||
# # Example
|
||||
# - replace stem with "share"
|
||||
# ```nushell
|
||||
# > "/usr/bin" | path with-stem "share"
|
||||
# /usr/share
|
||||
#
|
||||
# - replace stem with "nushell"
|
||||
# > ["/home/alice/", "/home/bob/secret.txt"] | path with-stem "nushell"
|
||||
# ╭───┬───────────────────────╮
|
||||
# │ 0 │ /home/nushell │
|
||||
# │ 1 │ /home/bob/nushell.txt │
|
||||
# ╰───┴───────────────────────╯
|
||||
# ```
|
||||
@example "replace stem with 'share'" {
|
||||
"/usr/bin" | path with-stem "share"
|
||||
} --result /usr/share
|
||||
@example "replace stem with 'nushell'" {
|
||||
["/home/alice/", "/home/bob/secret.txt"] | path with-stem "nushell"
|
||||
} --result [/home/nushell, /home/bob/nushell.txt]
|
||||
export def with-stem [stem: string] { with-field stem $stem }
|
||||
|
||||
alias "path with-parent" = with-parent
|
||||
|
||||
# Replace parent field of input file paths.
|
||||
#
|
||||
# # Example
|
||||
# - replace parent path with `/usr/share`
|
||||
# ```nushell
|
||||
# > "/etc/foobar" | path with-parent "/usr/share/"
|
||||
# /usr/share/foobar
|
||||
#
|
||||
# - replace parent path with `/root/` for all filenames in list
|
||||
# > ["/home/rose/meow", "/home/fdncred/"] | path with-parent "/root/"
|
||||
# ╭───┬───────────────╮
|
||||
# │ 0 │ /root/meow │
|
||||
# │ 1 │ /root/fdncred │
|
||||
# ╰───┴───────────────╯
|
||||
# ```
|
||||
@example "replace parent path with `/usr/share`" {
|
||||
"/etc/foobar" | path with-parent "/usr/share/"
|
||||
} --result "/usr/share/foobar"
|
||||
@example "replace parent path with `/root/` for all filenames in list" {
|
||||
["/home/rose/meow", "/home/fdncred/"] | path with-parent "/root/"
|
||||
} --result [/root/meow, /root/fdncred]
|
||||
export def with-parent [parent: string] { with-field parent $parent }
|
||||
|
Reference in New Issue
Block a user