mirror of
https://github.com/nushell/nushell.git
synced 2024-11-28 19:33:47 +01:00
Make trash support optional (#1572)
This commit is contained in:
parent
8ac9d781fd
commit
8e7e8c17e1
@ -62,7 +62,7 @@ nu-build = { version = "0.12.0", path = "./crates/nu-build" }
|
|||||||
test-bins = []
|
test-bins = []
|
||||||
|
|
||||||
default = ["sys", "ps", "textview", "inc", "str"]
|
default = ["sys", "ps", "textview", "inc", "str"]
|
||||||
stable = ["default", "starship-prompt", "binaryview", "match", "tree", "average", "post", "fetch", "clipboard-cli"]
|
stable = ["default", "starship-prompt", "binaryview", "match", "tree", "average", "post", "fetch", "clipboard-cli", "trash-support"]
|
||||||
|
|
||||||
# Default
|
# Default
|
||||||
textview = ["crossterm", "syntect", "url", "nu_plugin_textview"]
|
textview = ["crossterm", "syntect", "url", "nu_plugin_textview"]
|
||||||
@ -82,6 +82,7 @@ tree = ["nu_plugin_tree"]
|
|||||||
|
|
||||||
clipboard-cli = ["nu-cli/clipboard-cli"]
|
clipboard-cli = ["nu-cli/clipboard-cli"]
|
||||||
starship-prompt = ["nu-cli/starship-prompt"]
|
starship-prompt = ["nu-cli/starship-prompt"]
|
||||||
|
trash-support = ["nu-cli/trash-support"]
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "fail"
|
name = "fail"
|
||||||
|
@ -79,11 +79,11 @@ term = "0.5.2"
|
|||||||
termcolor = "1.1.0"
|
termcolor = "1.1.0"
|
||||||
textwrap = {version = "0.11.0", features = ["term_size"]}
|
textwrap = {version = "0.11.0", features = ["term_size"]}
|
||||||
toml = "0.5.6"
|
toml = "0.5.6"
|
||||||
trash = "1.0.0"
|
|
||||||
typetag = "0.1.4"
|
typetag = "0.1.4"
|
||||||
umask = "0.1"
|
umask = "0.1"
|
||||||
unicode-xid = "0.2.0"
|
unicode-xid = "0.2.0"
|
||||||
|
|
||||||
|
trash = { version = "1.0.0", optional = true }
|
||||||
clipboard = { version = "0.5", optional = true }
|
clipboard = { version = "0.5", optional = true }
|
||||||
starship = { version = "0.39.0", optional = true }
|
starship = { version = "0.39.0", optional = true }
|
||||||
|
|
||||||
@ -101,3 +101,4 @@ nu-build = { version = "0.12.0", path = "../nu-build" }
|
|||||||
stable = []
|
stable = []
|
||||||
starship-prompt = ["starship"]
|
starship-prompt = ["starship"]
|
||||||
clipboard-cli = ["clipboard"]
|
clipboard-cli = ["clipboard"]
|
||||||
|
trash-support = ["trash"]
|
@ -12,6 +12,7 @@ pub struct Remove;
|
|||||||
pub struct RemoveArgs {
|
pub struct RemoveArgs {
|
||||||
pub rest: Vec<Tagged<PathBuf>>,
|
pub rest: Vec<Tagged<PathBuf>>,
|
||||||
pub recursive: Tagged<bool>,
|
pub recursive: Tagged<bool>,
|
||||||
|
#[allow(unused)]
|
||||||
pub trash: Tagged<bool>,
|
pub trash: Tagged<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -946,7 +946,7 @@ impl Shell for FilesystemShell {
|
|||||||
RemoveArgs {
|
RemoveArgs {
|
||||||
rest: targets,
|
rest: targets,
|
||||||
recursive,
|
recursive,
|
||||||
trash,
|
trash: _trash,
|
||||||
}: RemoveArgs,
|
}: RemoveArgs,
|
||||||
name: Tag,
|
name: Tag,
|
||||||
path: &str,
|
path: &str,
|
||||||
@ -1024,16 +1024,30 @@ impl Shell for FilesystemShell {
|
|||||||
|
|
||||||
if let Ok(metadata) = f.symlink_metadata() {
|
if let Ok(metadata) = f.symlink_metadata() {
|
||||||
if metadata.is_file() || metadata.file_type().is_symlink() || recursive.item || is_empty() {
|
if metadata.is_file() || metadata.file_type().is_symlink() || recursive.item || is_empty() {
|
||||||
let result = if trash.item {
|
let result;
|
||||||
trash::remove(f)
|
#[cfg(feature = "trash-support")]
|
||||||
.map_err(|e| f.to_string_lossy())
|
{
|
||||||
} else if metadata.is_file() {
|
result = if _trash.item {
|
||||||
std::fs::remove_file(f)
|
trash::remove(f)
|
||||||
.map_err(|e| f.to_string_lossy())
|
.map_err(|e| f.to_string_lossy())
|
||||||
} else {
|
} else if metadata.is_file() {
|
||||||
std::fs::remove_dir_all(f)
|
std::fs::remove_file(f)
|
||||||
.map_err(|e| f.to_string_lossy())
|
.map_err(|e| f.to_string_lossy())
|
||||||
};
|
} else {
|
||||||
|
std::fs::remove_dir_all(f)
|
||||||
|
.map_err(|e| f.to_string_lossy())
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#[cfg(not(feature = "trash-support"))]
|
||||||
|
{
|
||||||
|
result = if metadata.is_file() {
|
||||||
|
std::fs::remove_file(f)
|
||||||
|
.map_err(|e| f.to_string_lossy())
|
||||||
|
} else {
|
||||||
|
std::fs::remove_dir_all(f)
|
||||||
|
.map_err(|e| f.to_string_lossy())
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
let msg = format!("Could not delete {:}", e);
|
let msg = format!("Could not delete {:}", e);
|
||||||
|
Loading…
Reference in New Issue
Block a user