mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 09:35:44 +02:00
Make get_full_help
take &dyn Command
(#12903)
# Description Changes `get_full_help` to take a `&dyn Command` instead of multiple arguments (`&Signature`, `&Examples` `is_parser_keyword`). All of these arguments can be gathered from a `Command`, so there is no need to pass the pieces to `get_full_help`. This PR also fixes an issue where the search terms are not shown if `--help` is used on a command.
This commit is contained in:
@ -29,16 +29,6 @@ impl Command for Bytes {
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
Ok(Value::string(
|
||||
get_full_help(
|
||||
&Bytes.signature(),
|
||||
&Bytes.examples(),
|
||||
engine_state,
|
||||
stack,
|
||||
self.is_keyword(),
|
||||
),
|
||||
call.head,
|
||||
)
|
||||
.into_pipeline_data())
|
||||
Ok(Value::string(get_full_help(self, engine_state, stack), call.head).into_pipeline_data())
|
||||
}
|
||||
}
|
||||
|
@ -29,16 +29,6 @@ impl Command for Into {
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
Ok(Value::string(
|
||||
get_full_help(
|
||||
&Into.signature(),
|
||||
&[],
|
||||
engine_state,
|
||||
stack,
|
||||
self.is_keyword(),
|
||||
),
|
||||
call.head,
|
||||
)
|
||||
.into_pipeline_data())
|
||||
Ok(Value::string(get_full_help(self, engine_state, stack), call.head).into_pipeline_data())
|
||||
}
|
||||
}
|
||||
|
@ -42,26 +42,6 @@ impl Command for Date {
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
date(engine_state, stack, call)
|
||||
Ok(Value::string(get_full_help(self, engine_state, stack), call.head).into_pipeline_data())
|
||||
}
|
||||
}
|
||||
|
||||
fn date(
|
||||
engine_state: &EngineState,
|
||||
stack: &mut Stack,
|
||||
call: &Call,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let head = call.head;
|
||||
|
||||
Ok(Value::string(
|
||||
get_full_help(
|
||||
&Date.signature(),
|
||||
&Date.examples(),
|
||||
engine_state,
|
||||
stack,
|
||||
false,
|
||||
),
|
||||
head,
|
||||
)
|
||||
.into_pipeline_data())
|
||||
}
|
||||
|
@ -29,16 +29,6 @@ impl Command for View {
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
Ok(Value::string(
|
||||
get_full_help(
|
||||
&View.signature(),
|
||||
&View.examples(),
|
||||
engine_state,
|
||||
stack,
|
||||
self.is_keyword(),
|
||||
),
|
||||
call.head,
|
||||
)
|
||||
.into_pipeline_data())
|
||||
Ok(Value::string(get_full_help(self, engine_state, stack), call.head).into_pipeline_data())
|
||||
}
|
||||
}
|
||||
|
12
crates/nu-command/src/env/config/config_.rs
vendored
12
crates/nu-command/src/env/config/config_.rs
vendored
@ -29,17 +29,7 @@ impl Command for ConfigMeta {
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
Ok(Value::string(
|
||||
get_full_help(
|
||||
&ConfigMeta.signature(),
|
||||
&ConfigMeta.examples(),
|
||||
engine_state,
|
||||
stack,
|
||||
self.is_keyword(),
|
||||
),
|
||||
call.head,
|
||||
)
|
||||
.into_pipeline_data())
|
||||
Ok(Value::string(get_full_help(self, engine_state, stack), call.head).into_pipeline_data())
|
||||
}
|
||||
|
||||
fn search_terms(&self) -> Vec<&str> {
|
||||
|
@ -29,16 +29,6 @@ impl Command for From {
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
Ok(Value::string(
|
||||
get_full_help(
|
||||
&From.signature(),
|
||||
&From.examples(),
|
||||
engine_state,
|
||||
stack,
|
||||
self.is_keyword(),
|
||||
),
|
||||
call.head,
|
||||
)
|
||||
.into_pipeline_data())
|
||||
Ok(Value::string(get_full_help(self, engine_state, stack), call.head).into_pipeline_data())
|
||||
}
|
||||
}
|
||||
|
@ -29,16 +29,6 @@ impl Command for To {
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
Ok(Value::string(
|
||||
get_full_help(
|
||||
&To.signature(),
|
||||
&To.examples(),
|
||||
engine_state,
|
||||
stack,
|
||||
self.is_keyword(),
|
||||
),
|
||||
call.head,
|
||||
)
|
||||
.into_pipeline_data())
|
||||
Ok(Value::string(get_full_help(self, engine_state, stack), call.head).into_pipeline_data())
|
||||
}
|
||||
}
|
||||
|
@ -29,16 +29,6 @@ impl Command for Hash {
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
Ok(Value::string(
|
||||
get_full_help(
|
||||
&Self.signature(),
|
||||
&Self.examples(),
|
||||
engine_state,
|
||||
stack,
|
||||
self.is_keyword(),
|
||||
),
|
||||
call.head,
|
||||
)
|
||||
.into_pipeline_data())
|
||||
Ok(Value::string(get_full_help(self, engine_state, stack), call.head).into_pipeline_data())
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
use crate::help::highlight_search_in_table;
|
||||
use nu_color_config::StyleComputer;
|
||||
use nu_engine::{command_prelude::*, get_full_help};
|
||||
use nu_protocol::engine::CommandType;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct HelpCommands;
|
||||
@ -89,18 +88,13 @@ pub fn help_commands(
|
||||
}
|
||||
|
||||
let output = engine_state
|
||||
.get_signatures_with_examples(false)
|
||||
.iter()
|
||||
.filter(|(signature, _, _)| signature.name == name)
|
||||
.map(|(signature, examples, cmd_type)| {
|
||||
get_full_help(
|
||||
signature,
|
||||
examples,
|
||||
engine_state,
|
||||
stack,
|
||||
cmd_type == &CommandType::Keyword,
|
||||
)
|
||||
.get_decls_sorted(false)
|
||||
.into_iter()
|
||||
.filter_map(|(_, decl_id)| {
|
||||
let decl = engine_state.get_decl(decl_id);
|
||||
(decl.name() == name).then_some(decl)
|
||||
})
|
||||
.map(|cmd| get_full_help(cmd, engine_state, stack))
|
||||
.collect::<Vec<String>>();
|
||||
|
||||
if !output.is_empty() {
|
||||
|
@ -1,7 +1,6 @@
|
||||
use crate::help::highlight_search_in_table;
|
||||
use nu_color_config::StyleComputer;
|
||||
use nu_engine::{command_prelude::*, get_full_help, scope::ScopeData};
|
||||
use nu_protocol::engine::CommandType;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct HelpExterns;
|
||||
@ -109,18 +108,13 @@ pub fn help_externs(
|
||||
}
|
||||
|
||||
let output = engine_state
|
||||
.get_signatures_with_examples(false)
|
||||
.iter()
|
||||
.filter(|(signature, _, _)| signature.name == name)
|
||||
.map(|(signature, examples, cmd_type)| {
|
||||
get_full_help(
|
||||
signature,
|
||||
examples,
|
||||
engine_state,
|
||||
stack,
|
||||
cmd_type == &CommandType::Keyword,
|
||||
)
|
||||
.get_decls_sorted(false)
|
||||
.into_iter()
|
||||
.filter_map(|(_, decl_id)| {
|
||||
let decl = engine_state.get_decl(decl_id);
|
||||
(decl.name() == name).then_some(decl)
|
||||
})
|
||||
.map(|cmd| get_full_help(cmd, engine_state, stack))
|
||||
.collect::<Vec<String>>();
|
||||
|
||||
if !output.is_empty() {
|
||||
|
@ -149,6 +149,7 @@ pub fn help_modules(
|
||||
if !module.decls.is_empty() || module.main.is_some() {
|
||||
let commands: Vec<(Vec<u8>, DeclId)> = engine_state
|
||||
.get_decls_sorted(false)
|
||||
.into_iter()
|
||||
.filter(|(_, id)| !engine_state.get_decl(*id).is_alias())
|
||||
.collect();
|
||||
|
||||
@ -186,6 +187,7 @@ pub fn help_modules(
|
||||
if !module.decls.is_empty() {
|
||||
let aliases: Vec<(Vec<u8>, DeclId)> = engine_state
|
||||
.get_decls_sorted(false)
|
||||
.into_iter()
|
||||
.filter(|(_, id)| engine_state.get_decl(*id).is_alias())
|
||||
.collect();
|
||||
|
||||
|
@ -29,16 +29,6 @@ impl Command for MathCommand {
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
Ok(Value::string(
|
||||
get_full_help(
|
||||
&MathCommand.signature(),
|
||||
&MathCommand.examples(),
|
||||
engine_state,
|
||||
stack,
|
||||
self.is_keyword(),
|
||||
),
|
||||
call.head,
|
||||
)
|
||||
.into_pipeline_data())
|
||||
Ok(Value::string(get_full_help(self, engine_state, stack), call.head).into_pipeline_data())
|
||||
}
|
||||
}
|
||||
|
@ -35,16 +35,6 @@ impl Command for Http {
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
Ok(Value::string(
|
||||
get_full_help(
|
||||
&Http.signature(),
|
||||
&Http.examples(),
|
||||
engine_state,
|
||||
stack,
|
||||
self.is_keyword(),
|
||||
),
|
||||
call.head,
|
||||
)
|
||||
.into_pipeline_data())
|
||||
Ok(Value::string(get_full_help(self, engine_state, stack), call.head).into_pipeline_data())
|
||||
}
|
||||
}
|
||||
|
@ -33,16 +33,6 @@ impl Command for Url {
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
Ok(Value::string(
|
||||
get_full_help(
|
||||
&Url.signature(),
|
||||
&Url.examples(),
|
||||
engine_state,
|
||||
stack,
|
||||
self.is_keyword(),
|
||||
),
|
||||
call.head,
|
||||
)
|
||||
.into_pipeline_data())
|
||||
Ok(Value::string(get_full_help(self, engine_state, stack), call.head).into_pipeline_data())
|
||||
}
|
||||
}
|
||||
|
@ -42,16 +42,6 @@ the path literal."#
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
Ok(Value::string(
|
||||
get_full_help(
|
||||
&PathCommand.signature(),
|
||||
&PathCommand.examples(),
|
||||
engine_state,
|
||||
stack,
|
||||
self.is_keyword(),
|
||||
),
|
||||
call.head,
|
||||
)
|
||||
.into_pipeline_data())
|
||||
Ok(Value::string(get_full_help(self, engine_state, stack), call.head).into_pipeline_data())
|
||||
}
|
||||
}
|
||||
|
@ -33,16 +33,6 @@ impl Command for RandomCommand {
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
Ok(Value::string(
|
||||
get_full_help(
|
||||
&RandomCommand.signature(),
|
||||
&RandomCommand.examples(),
|
||||
engine_state,
|
||||
stack,
|
||||
self.is_keyword(),
|
||||
),
|
||||
call.head,
|
||||
)
|
||||
.into_pipeline_data())
|
||||
Ok(Value::string(get_full_help(self, engine_state, stack), call.head).into_pipeline_data())
|
||||
}
|
||||
}
|
||||
|
@ -29,16 +29,6 @@ impl Command for Stor {
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
Ok(Value::string(
|
||||
get_full_help(
|
||||
&Stor.signature(),
|
||||
&Stor.examples(),
|
||||
engine_state,
|
||||
stack,
|
||||
self.is_keyword(),
|
||||
),
|
||||
call.head,
|
||||
)
|
||||
.into_pipeline_data())
|
||||
Ok(Value::string(get_full_help(self, engine_state, stack), call.head).into_pipeline_data())
|
||||
}
|
||||
}
|
||||
|
@ -29,16 +29,6 @@ impl Command for Format {
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
Ok(Value::string(
|
||||
get_full_help(
|
||||
&Format.signature(),
|
||||
&Format.examples(),
|
||||
engine_state,
|
||||
stack,
|
||||
self.is_keyword(),
|
||||
),
|
||||
call.head,
|
||||
)
|
||||
.into_pipeline_data())
|
||||
Ok(Value::string(get_full_help(self, engine_state, stack), call.head).into_pipeline_data())
|
||||
}
|
||||
}
|
||||
|
@ -29,16 +29,6 @@ impl Command for SplitCommand {
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
Ok(Value::string(
|
||||
get_full_help(
|
||||
&SplitCommand.signature(),
|
||||
&SplitCommand.examples(),
|
||||
engine_state,
|
||||
stack,
|
||||
self.is_keyword(),
|
||||
),
|
||||
call.head,
|
||||
)
|
||||
.into_pipeline_data())
|
||||
Ok(Value::string(get_full_help(self, engine_state, stack), call.head).into_pipeline_data())
|
||||
}
|
||||
}
|
||||
|
@ -29,16 +29,6 @@ impl Command for Str {
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
Ok(Value::string(
|
||||
get_full_help(
|
||||
&Str.signature(),
|
||||
&Str.examples(),
|
||||
engine_state,
|
||||
stack,
|
||||
self.is_keyword(),
|
||||
),
|
||||
call.head,
|
||||
)
|
||||
.into_pipeline_data())
|
||||
Ok(Value::string(get_full_help(self, engine_state, stack), call.head).into_pipeline_data())
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user