mirror of
https://github.com/nushell/nushell.git
synced 2025-05-19 22:23:22 +00:00
with the `help` command to explore and list all commands available. Enter will also try to see if the location to be entered is an existing Nu command, if it is it will let you inspect the command under `help`. This provides baseline needed so we can iterate on it.
77 lines
2.0 KiB
Rust
77 lines
2.0 KiB
Rust
use crate::errors::ShellError;
|
|
use crate::object::Value;
|
|
use crate::prelude::*;
|
|
|
|
use crate::commands::WholeStreamCommand;
|
|
use crate::parser::registry::Signature;
|
|
|
|
pub struct Which;
|
|
|
|
impl WholeStreamCommand for Which {
|
|
fn name(&self) -> &str {
|
|
"which"
|
|
}
|
|
|
|
fn signature(&self) -> Signature {
|
|
Signature::build("which")
|
|
.required("name", SyntaxType::Any)
|
|
}
|
|
|
|
fn usage(&self) -> &str {
|
|
"Finds a program file."
|
|
}
|
|
|
|
fn run(
|
|
&self,
|
|
args: CommandArgs,
|
|
registry: &CommandRegistry,
|
|
) -> Result<OutputStream, ShellError> {
|
|
which(args, registry)
|
|
}
|
|
}
|
|
|
|
pub fn which(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
|
|
let args = args.evaluate_once(registry)?;
|
|
|
|
let mut which_out = VecDeque::new();
|
|
let span = args.call_info.name_span;
|
|
|
|
if let Some(v) = &args.call_info.args.positional {
|
|
if v.len() > 0 {
|
|
match &v[0] {
|
|
Tagged {
|
|
item: Value::Primitive(Primitive::String(s)),
|
|
tag,
|
|
} => match which::which(&s) {
|
|
Ok(ok) => {
|
|
which_out
|
|
.push_back(Value::Primitive(Primitive::Path(ok)).tagged(tag.clone()));
|
|
}
|
|
_ => {}
|
|
},
|
|
Tagged { tag, .. } => {
|
|
return Err(ShellError::labeled_error(
|
|
"Expected a filename to find",
|
|
"needs a filename",
|
|
tag.span,
|
|
));
|
|
}
|
|
}
|
|
} else {
|
|
return Err(ShellError::labeled_error(
|
|
"Expected a binary to find",
|
|
"needs application name",
|
|
span,
|
|
));
|
|
}
|
|
} else {
|
|
return Err(ShellError::labeled_error(
|
|
"Expected a binary to find",
|
|
"needs application name",
|
|
span,
|
|
));
|
|
}
|
|
|
|
Ok(which_out.to_output_stream())
|
|
}
|