2020-11-24 10:18:38 +01:00
|
|
|
mod basename;
|
|
|
|
mod dirname;
|
|
|
|
mod exists;
|
|
|
|
mod expand;
|
2021-03-04 08:04:56 +01:00
|
|
|
mod join;
|
Path Enhancement Project #2: parse, join and split (#3256)
* Add new path parse subcommand
This includes a slight refactor to all the path subcommand `action()`
functions.
* Remove filestem and extension; Fix example
* Add additional description to path parse
* Put join arg behind flag; Fix missing import (Win)
* Fix error when column path is passed as arg
* Add structured path joining
Structured path is implicitly joined at every patch subcommand call.
* Fix existing path join tests; Fix rustfmt
* Remove redundant 'static lifetime (clippy)
* Add initial impl of path split subcommand
* Add ability to join path from parts
* Fix wrong results in path split examples
* Fix remaining asyncs after engine change
* Do not wrap split path parts into table
When the input is just a list of values, the `path split` command will
split each value directly into the output stream, similar to
`split-row`. Column path--specified values are still wrapped into a
table so they can still be used to replace table fields.
* Join list of values instead of going one-by-one
When `path join` encounters a list of values, it attempts to join them,
instead of going one-by-one like the rest of the path commands. You can
still `each { echo $it | path join }` to join them one-by-one, if the
values are, e.g., tables.
Now, the behavior of `path split` and `path join` should match the
`split-row` and `str collect` counterparts and should hopefully align
better with user's expectations.
* Make sure path join detects structured path
* Fix panic on empty input stream
Also, doesn't collect input into vector unnecessarily.
* Fix path join not appending value
* Remove argument serialization
* Make better errors; Misc refactor
* OsStr -> String encoding is now lossy, instead of throwing an error
* The consequence is action() now always returns Value instead of Result
* Removed redundant handle_value() call in `path join`
* Fix possible incorrect error detection in `path split`
* Applied rustfmt + clippy
* Add more usage, examples & test; Fix type error
The 'parent' column was required to be a path but didn't work with
string.
* Add more help & examples; Maybe fix Windows error
* Refactor operate function
Reducing code repetition
* Review usages and examples
* Add the option to manually specify the extension
* Add more tests; Fix failures on Windows
* Move path commands to engine-p
* Small refactor
2021-04-20 08:45:28 +02:00
|
|
|
mod parse;
|
|
|
|
mod split;
|
2020-11-24 10:18:38 +01:00
|
|
|
mod type_;
|
|
|
|
|
2023-08-29 22:18:52 +02:00
|
|
|
use nu_test_support::nu;
|
2020-11-24 10:18:38 +01:00
|
|
|
use std::path::MAIN_SEPARATOR;
|
|
|
|
|
|
|
|
/// Helper function that joins string literals with '/' or '\', based on host OS
|
|
|
|
fn join_path_sep(pieces: &[&str]) -> String {
|
|
|
|
let sep_string = String::from(MAIN_SEPARATOR);
|
|
|
|
pieces.join(&sep_string)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(windows)]
|
|
|
|
#[test]
|
|
|
|
fn joins_path_on_windows() {
|
|
|
|
let pieces = ["sausage", "bacon", "spam"];
|
|
|
|
let actual = join_path_sep(&pieces);
|
|
|
|
|
|
|
|
assert_eq!(&actual, "sausage\\bacon\\spam");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(windows))]
|
|
|
|
#[test]
|
|
|
|
fn joins_path_on_other_than_windows() {
|
|
|
|
let pieces = ["sausage", "bacon", "spam"];
|
|
|
|
let actual = join_path_sep(&pieces);
|
|
|
|
|
|
|
|
assert_eq!(&actual, "sausage/bacon/spam");
|
|
|
|
}
|
2023-08-26 15:41:29 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn const_path_relative_to() {
|
|
|
|
let actual = nu!("'/home/viking' | path relative-to '/home'");
|
|
|
|
assert_eq!(actual.out, "viking");
|
|
|
|
}
|