forked from extern/nushell
Better error message when rm can't find files (#7098)
This commit is contained in:
parent
13515c5eb0
commit
cb926f7b49
@ -197,10 +197,24 @@ fn rm(
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let targets_span = Span {
|
||||||
|
start: targets
|
||||||
|
.iter()
|
||||||
|
.map(|x| x.span.start)
|
||||||
|
.min()
|
||||||
|
.expect("targets were empty"),
|
||||||
|
end: targets
|
||||||
|
.iter()
|
||||||
|
.map(|x| x.span.end)
|
||||||
|
.max()
|
||||||
|
.expect("targets were empty"),
|
||||||
|
};
|
||||||
|
|
||||||
let path = current_dir(engine_state, stack)?;
|
let path = current_dir(engine_state, stack)?;
|
||||||
|
|
||||||
let (mut target_exists, mut empty_span) = (false, call.head);
|
let (mut target_exists, mut empty_span) = (false, call.head);
|
||||||
let mut all_targets: HashMap<PathBuf, Span> = HashMap::new();
|
let mut all_targets: HashMap<PathBuf, Span> = HashMap::new();
|
||||||
|
|
||||||
for target in targets {
|
for target in targets {
|
||||||
if path.to_string_lossy() == target.item
|
if path.to_string_lossy() == target.item
|
||||||
|| path.as_os_str().to_string_lossy().starts_with(&format!(
|
|| path.as_os_str().to_string_lossy().starts_with(&format!(
|
||||||
@ -275,9 +289,9 @@ fn rm(
|
|||||||
|
|
||||||
if all_targets.is_empty() && !force {
|
if all_targets.is_empty() && !force {
|
||||||
return Err(ShellError::GenericError(
|
return Err(ShellError::GenericError(
|
||||||
"No valid paths".into(),
|
"File(s) not found".into(),
|
||||||
"no valid paths".into(),
|
"File(s) not found".into(),
|
||||||
Some(empty_span),
|
Some(targets_span),
|
||||||
None,
|
None,
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
));
|
));
|
||||||
|
Loading…
Reference in New Issue
Block a user