remove without check path exist, rm -f (#2590)

This commit is contained in:
Luccas Mateus
2020-09-22 18:11:31 -03:00
committed by GitHub
parent ebba89ea31
commit e8ec5027ff
3 changed files with 21 additions and 2 deletions

View File

@ -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,
}
]
}
}

View File

@ -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",