mirror of
https://github.com/nushell/nushell.git
synced 2024-12-22 15:13:01 +01:00
can view list of commands for details.
This commit is contained in:
parent
030d73147e
commit
b031d4cd77
@ -1,6 +1,7 @@
|
||||
use crate::commands::command::CommandAction;
|
||||
use crate::commands::PerItemCommand;
|
||||
use crate::errors::ShellError;
|
||||
use crate::object::{command_dict, TaggedDictBuilder};
|
||||
use crate::parser::registry;
|
||||
use crate::prelude::*;
|
||||
|
||||
@ -22,34 +23,50 @@ impl PerItemCommand for Help {
|
||||
fn run(
|
||||
&self,
|
||||
call_info: &CallInfo,
|
||||
_registry: &CommandRegistry,
|
||||
registry: &CommandRegistry,
|
||||
_raw_args: &RawCommandArgs,
|
||||
_input: Tagged<Value>,
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
let span = call_info.name_span;
|
||||
|
||||
if call_info.args.len() == 0 {
|
||||
return Ok(
|
||||
vec![
|
||||
Ok(ReturnSuccess::Action(
|
||||
CommandAction::EnterHelpShell(
|
||||
Tagged::from_simple_spanned_item(Value::nothing(), span)
|
||||
)))].into()
|
||||
)
|
||||
return Ok(vec![Ok(ReturnSuccess::Action(CommandAction::EnterHelpShell(
|
||||
Tagged::from_simple_spanned_item(Value::nothing(), span),
|
||||
)))]
|
||||
.into());
|
||||
}
|
||||
|
||||
match call_info.args.expect_nth(0)? {
|
||||
Tagged {
|
||||
item: Value::Primitive(Primitive::String(document)),
|
||||
..
|
||||
} => Ok(vec![Ok(ReturnSuccess::Action(CommandAction::EnterHelpShell(
|
||||
Tagged::from_simple_spanned_item(Value::string(document), span)
|
||||
tag,
|
||||
} => {
|
||||
if document == "commands" {
|
||||
let mut specs = VecDeque::new();
|
||||
|
||||
for cmd in registry.names() {
|
||||
let mut spec = TaggedDictBuilder::new(tag.clone());
|
||||
let value = command_dict(registry.get_command(&cmd).unwrap(), tag.clone());
|
||||
|
||||
spec.insert("name", cmd);
|
||||
spec.insert(
|
||||
"description",
|
||||
value.get_data_by_key("usage").unwrap().as_string().unwrap(),
|
||||
);
|
||||
spec.insert_tagged("details", value);
|
||||
|
||||
specs.push_back(ReturnSuccess::value(spec.into_tagged_value()));
|
||||
}
|
||||
|
||||
return Ok(specs.to_output_stream());
|
||||
}
|
||||
|
||||
Ok(OutputStream::empty())
|
||||
}
|
||||
x => Ok(vec![Ok(ReturnSuccess::Action(CommandAction::EnterHelpShell(
|
||||
x.clone(),
|
||||
)))]
|
||||
.into()),
|
||||
x => Ok(
|
||||
vec![Ok(ReturnSuccess::Action(CommandAction::EnterHelpShell(x.clone())))]
|
||||
.into(),
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user