mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 14:40:06 +02:00
Remove old nushell/merge engine-q
This commit is contained in:
@ -1,22 +1,11 @@
|
||||
[package]
|
||||
authors = ["The Nu Project Contributors"]
|
||||
description = "Path handling library for Nushell"
|
||||
<<<<<<< HEAD
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
name = "nu-path"
|
||||
version = "0.43.0"
|
||||
=======
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
name = "nu-path"
|
||||
version = "0.37.1"
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
version = "0.59.0"
|
||||
|
||||
[dependencies]
|
||||
dirs-next = "2.0.0"
|
||||
dunce = "1.0.1"
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
|
3
crates/nu-path/README.md
Normal file
3
crates/nu-path/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# nu-path
|
||||
|
||||
This crate takes care of path handling in Nushell, such as canonicalization and component expansion, as well as other path-related utilities.
|
@ -19,11 +19,7 @@ fn handle_dots_push(string: &mut String, count: u8) {
|
||||
string.pop(); // remove last '/'
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
/// Expands any occurrence of more than two dots into a sequence of ../ (or ..\ on windows), e.g.,
|
||||
=======
|
||||
/// Expands any occurence of more than two dots into a sequence of ../ (or ..\ on windows), e.g.,
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
/// "..." into "../..", "...." into "../../../", etc.
|
||||
pub fn expand_ndots(path: impl AsRef<Path>) -> PathBuf {
|
||||
// Check if path is valid UTF-8 and if not, return it as it is to avoid breaking it via string
|
||||
|
@ -26,32 +26,19 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
/// Resolve all symbolic links and all components (tilde, ., .., ...+) and return the path in its
|
||||
/// absolute form.
|
||||
///
|
||||
/// Fails under the same conditions as
|
||||
/// [std::fs::canonicalize](https://doc.rust-lang.org/std/fs/fn.canonicalize.html).
|
||||
pub fn canonicalize(path: impl AsRef<Path>) -> io::Result<PathBuf> {
|
||||
=======
|
||||
fn canonicalize(path: impl AsRef<Path>) -> io::Result<PathBuf> {
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
let path = expand_tilde(path);
|
||||
let path = expand_ndots(path);
|
||||
|
||||
dunce::canonicalize(path)
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
/// Same as canonicalize() but the input path is specified relative to another path
|
||||
=======
|
||||
/// Resolve all symbolic links and all components (tilde, ., .., ...+) and return the path in its
|
||||
/// absolute form.
|
||||
///
|
||||
/// Fails under the same conditions as
|
||||
/// [std::fs::canonicalize](https://doc.rust-lang.org/std/fs/fn.canonicalize.html).
|
||||
/// The input path is specified relative to another path
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
pub fn canonicalize_with<P, Q>(path: P, relative_to: Q) -> io::Result<PathBuf>
|
||||
where
|
||||
P: AsRef<Path>,
|
||||
@ -62,15 +49,12 @@ where
|
||||
canonicalize(path)
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
fn expand_path(path: impl AsRef<Path>) -> PathBuf {
|
||||
let path = expand_tilde(path);
|
||||
let path = expand_ndots(path);
|
||||
expand_dots(path)
|
||||
}
|
||||
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
/// Resolve only path components (tilde, ., .., ...+), if possible.
|
||||
///
|
||||
/// The function works in a "best effort" mode: It does not fail but rather returns the unexpanded
|
||||
@ -79,17 +63,7 @@ fn expand_path(path: impl AsRef<Path>) -> PathBuf {
|
||||
/// Furthermore, unlike canonicalize(), it does not use sys calls (such as readlink).
|
||||
///
|
||||
/// Does not convert to absolute form nor does it resolve symlinks.
|
||||
<<<<<<< HEAD
|
||||
pub fn expand_path(path: impl AsRef<Path>) -> PathBuf {
|
||||
let path = expand_tilde(path);
|
||||
let path = expand_ndots(path);
|
||||
expand_dots(path)
|
||||
}
|
||||
|
||||
/// Same as expand_path() but the input path is specified relative to another path
|
||||
=======
|
||||
/// The input path is specified relative to another path
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
pub fn expand_path_with<P, Q>(path: P, relative_to: Q) -> PathBuf
|
||||
where
|
||||
P: AsRef<Path>,
|
||||
|
@ -1,17 +1,10 @@
|
||||
mod dots;
|
||||
mod expansions;
|
||||
<<<<<<< HEAD
|
||||
mod tilde;
|
||||
mod util;
|
||||
|
||||
pub use expansions::{canonicalize, canonicalize_with, expand_path, expand_path_with};
|
||||
=======
|
||||
mod helpers;
|
||||
mod tilde;
|
||||
mod util;
|
||||
|
||||
pub use expansions::{canonicalize_with, expand_path_with};
|
||||
pub use helpers::{config_dir, home_dir};
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
pub use tilde::expand_tilde;
|
||||
pub use util::trim_trailing_slash;
|
||||
|
@ -1,10 +1,6 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
<<<<<<< HEAD
|
||||
fn expand_tilde_with(path: impl AsRef<Path>, home: Option<PathBuf>) -> PathBuf {
|
||||
=======
|
||||
fn expand_tilde_with_home(path: impl AsRef<Path>, home: Option<PathBuf>) -> PathBuf {
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
let path = path.as_ref();
|
||||
|
||||
if !path.starts_with("~") {
|
||||
@ -31,11 +27,7 @@ fn expand_tilde_with_home(path: impl AsRef<Path>, home: Option<PathBuf>) -> Path
|
||||
/// Expand tilde ("~") into a home directory if it is the first path component
|
||||
pub fn expand_tilde(path: impl AsRef<Path>) -> PathBuf {
|
||||
// TODO: Extend this to work with "~user" style of home paths
|
||||
<<<<<<< HEAD
|
||||
expand_tilde_with(path, dirs_next::home_dir())
|
||||
=======
|
||||
expand_tilde_with_home(path, dirs_next::home_dir())
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@ -45,29 +37,17 @@ mod tests {
|
||||
fn check_expanded(s: &str) {
|
||||
let home = Path::new("/home");
|
||||
let buf = Some(PathBuf::from(home));
|
||||
<<<<<<< HEAD
|
||||
assert!(expand_tilde_with(Path::new(s), buf).starts_with(&home));
|
||||
=======
|
||||
assert!(expand_tilde_with_home(Path::new(s), buf).starts_with(&home));
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
|
||||
// Tests the special case in expand_tilde for "/" as home
|
||||
let home = Path::new("/");
|
||||
let buf = Some(PathBuf::from(home));
|
||||
<<<<<<< HEAD
|
||||
assert!(!expand_tilde_with(Path::new(s), buf).starts_with("//"));
|
||||
=======
|
||||
assert!(!expand_tilde_with_home(Path::new(s), buf).starts_with("//"));
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
}
|
||||
|
||||
fn check_not_expanded(s: &str) {
|
||||
let home = PathBuf::from("/home");
|
||||
<<<<<<< HEAD
|
||||
let expanded = expand_tilde_with(Path::new(s), Some(home));
|
||||
=======
|
||||
let expanded = expand_tilde_with_home(Path::new(s), Some(home));
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
assert!(expanded == Path::new(s));
|
||||
}
|
||||
|
||||
|
4
crates/nu-path/src/util.rs
Normal file
4
crates/nu-path/src/util.rs
Normal file
@ -0,0 +1,4 @@
|
||||
/// Trim trailing path separator from a string
|
||||
pub fn trim_trailing_slash(s: &str) -> &str {
|
||||
s.trim_end_matches(std::path::is_separator)
|
||||
}
|
1
crates/nu-path/tests/mod.rs
Normal file
1
crates/nu-path/tests/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
mod util;
|
45
crates/nu-path/tests/util.rs
Normal file
45
crates/nu-path/tests/util.rs
Normal file
@ -0,0 +1,45 @@
|
||||
use nu_path::trim_trailing_slash;
|
||||
use std::path::MAIN_SEPARATOR;
|
||||
|
||||
/// Helper function that joins string literals with '/' or '\', based on the host OS
|
||||
fn join_path_sep(pieces: &[&str]) -> String {
|
||||
let sep_string = String::from(MAIN_SEPARATOR);
|
||||
pieces.join(&sep_string)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trims_trailing_slash_without_trailing_slash() {
|
||||
let path = join_path_sep(&["some", "path"]);
|
||||
|
||||
let actual = trim_trailing_slash(&path);
|
||||
|
||||
assert_eq!(actual, &path)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trims_trailing_slash() {
|
||||
let path = join_path_sep(&["some", "path", ""]);
|
||||
|
||||
let actual = trim_trailing_slash(&path);
|
||||
let expected = join_path_sep(&["some", "path"]);
|
||||
|
||||
assert_eq!(actual, &expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trims_many_trailing_slashes() {
|
||||
let path = join_path_sep(&["some", "path", "", "", "", ""]);
|
||||
|
||||
let actual = trim_trailing_slash(&path);
|
||||
let expected = join_path_sep(&["some", "path"]);
|
||||
|
||||
assert_eq!(actual, &expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trims_trailing_slash_empty() {
|
||||
let path = String::from(MAIN_SEPARATOR);
|
||||
let actual = trim_trailing_slash(&path);
|
||||
|
||||
assert_eq!(actual, "")
|
||||
}
|
Reference in New Issue
Block a user