mirror of
https://github.com/nushell/nushell.git
synced 2025-04-09 21:28:55 +02:00
Simplify and improve listing for which. (#1510)
* Simplified implementation * Show executables, even if the current user doesn't have permissions to execute them.
This commit is contained in:
parent
a7ec00a037
commit
36b5d063c1
@ -87,66 +87,24 @@ fn which(
|
|||||||
application.item.clone()
|
application.item.clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
if all {
|
let stream = async_stream! {
|
||||||
let stream = async_stream! {
|
if !external {
|
||||||
if external {
|
|
||||||
if let Ok(Some(path)) = ichwh::which(&item).await {
|
|
||||||
yield ReturnSuccess::value(entry_path!(item, path.into(), application.tag.clone()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let builtin = commands.has(&item);
|
let builtin = commands.has(&item);
|
||||||
if builtin {
|
if builtin {
|
||||||
yield ReturnSuccess::value(entry_builtin!(item, application.tag.clone()));
|
yield ReturnSuccess::value(entry_builtin!(item, application.tag.clone()));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if let Ok(paths) = ichwh::which_all(&item).await {
|
if let Ok(paths) = ichwh::which_all(&item).await {
|
||||||
if !builtin && paths.len() == 0 {
|
for path in paths {
|
||||||
yield Err(ShellError::labeled_error(
|
yield ReturnSuccess::value(entry_path!(item, path.into(), application.tag.clone()));
|
||||||
"Binary not found for argument, and argument is not a builtin",
|
|
||||||
"not found",
|
|
||||||
&application.tag,
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
for path in paths {
|
|
||||||
yield ReturnSuccess::value(entry_path!(item, path.into(), application.tag.clone()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
yield Err(ShellError::labeled_error(
|
|
||||||
"Error trying to find binary for argument",
|
|
||||||
"error",
|
|
||||||
&application.tag,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if all {
|
||||||
Ok(stream.to_output_stream())
|
Ok(stream.to_output_stream())
|
||||||
} else {
|
} else {
|
||||||
let stream = async_stream! {
|
Ok(stream.take(1).to_output_stream())
|
||||||
if external {
|
|
||||||
if let Ok(Some(path)) = ichwh::which(&item).await {
|
|
||||||
yield ReturnSuccess::value(entry_path!(item, path.into(), application.tag.clone()));
|
|
||||||
}
|
|
||||||
} else if commands.has(&item) {
|
|
||||||
yield ReturnSuccess::value(entry_builtin!(item, application.tag.clone()));
|
|
||||||
} else {
|
|
||||||
match ichwh::which(&item).await {
|
|
||||||
Ok(Some(path)) => yield ReturnSuccess::value(entry_path!(item, path.into(), application.tag.clone())),
|
|
||||||
Ok(None) => yield Err(ShellError::labeled_error(
|
|
||||||
"Binary not found for argument, and argument is not a builtin",
|
|
||||||
"not found",
|
|
||||||
&application.tag,
|
|
||||||
)),
|
|
||||||
Err(_) => yield Err(ShellError::labeled_error(
|
|
||||||
"Error trying to find binary for argument",
|
|
||||||
"error",
|
|
||||||
&application.tag,
|
|
||||||
)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(stream.to_output_stream())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user