forked from extern/nushell
remove without check path exist, rm -f
(#2590)
This commit is contained in:
parent
ebba89ea31
commit
e8ec5027ff
@ -16,6 +16,7 @@ pub struct RemoveArgs {
|
||||
pub trash: Tagged<bool>,
|
||||
#[allow(unused)]
|
||||
pub permanent: Tagged<bool>,
|
||||
pub force: Tagged<bool>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@ -37,6 +38,7 @@ impl WholeStreamCommand for Remove {
|
||||
Some('p'),
|
||||
)
|
||||
.switch("recursive", "delete subdirectories recursively", Some('r'))
|
||||
.switch("force", "suppress error when no file", Some('f'))
|
||||
.rest(SyntaxShape::Pattern, "the file path(s) to remove")
|
||||
}
|
||||
|
||||
@ -69,6 +71,11 @@ impl WholeStreamCommand for Remove {
|
||||
example: "rm --permanent file.txt",
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description: "Delete a file, and suppress errors if no file is found",
|
||||
example: "rm --force file.txt",
|
||||
result: None,
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -496,6 +496,7 @@ impl Shell for FilesystemShell {
|
||||
recursive,
|
||||
trash: _trash,
|
||||
permanent: _permanent,
|
||||
force: _force,
|
||||
}: RemoveArgs,
|
||||
name: Tag,
|
||||
path: &str,
|
||||
@ -556,7 +557,7 @@ impl Shell for FilesystemShell {
|
||||
};
|
||||
}
|
||||
|
||||
if all_targets.is_empty() {
|
||||
if all_targets.is_empty() && !_force.item {
|
||||
return Err(ShellError::labeled_error(
|
||||
"No valid paths",
|
||||
"no valid paths",
|
||||
|
@ -125,7 +125,6 @@ fn removes_directory_contents_with_recursive_flag() {
|
||||
fn errors_if_attempting_to_delete_a_directory_with_content_without_recursive_flag() {
|
||||
Playground::setup("rm_test_6", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![EmptyFile("some_empty_file.txt")]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.root(),
|
||||
"rm rm_test_6"
|
||||
@ -265,3 +264,15 @@ fn remove_files_from_two_parents_up_using_multiple_dots_and_glob() {
|
||||
));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_errors_if_attempting_to_delete_non_existent_file_with_f_flag() {
|
||||
Playground::setup("rm_test_14", |dirs, _| {
|
||||
let actual = nu!(
|
||||
cwd: dirs.root(),
|
||||
"rm -f non_existent_file.txt"
|
||||
);
|
||||
|
||||
assert!(!actual.err.contains("no valid path"));
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user