mirror of
https://github.com/nushell/nushell.git
synced 2024-12-02 05:13:56 +01:00
1d1ec4727a
* Refactor path subcommand argument handling DefaultArguments are no longer passed to each subcommand. Instead, each subcommand has its own Path<xxx>Arguments. This means that it is no longer necessary to edit every single path subcommand source file when changing the arguments struct. * Add new path join subcommand Makes it easier to create new paths. It's just a wrapper around Rust's Path.join().
35 lines
745 B
Rust
35 lines
745 B
Rust
mod basename;
|
|
mod dirname;
|
|
mod exists;
|
|
mod expand;
|
|
mod extension;
|
|
mod filestem;
|
|
mod join;
|
|
mod type_;
|
|
|
|
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");
|
|
}
|