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:
Ian Manske
2024-05-19 17:56:33 +00:00
committed by GitHub
parent 474293bf1c
commit baeba19b22
36 changed files with 82 additions and 413 deletions

View File

@ -2,18 +2,16 @@ use crate::eval_call;
use nu_protocol::{
ast::{Argument, Call, Expr, Expression, RecordItem},
debugger::WithoutDebug,
engine::{EngineState, Stack},
engine::{Command, EngineState, Stack},
record, Category, Example, IntoPipelineData, PipelineData, Signature, Span, SyntaxShape, Type,
Value,
};
use std::{collections::HashMap, fmt::Write};
pub fn get_full_help(
sig: &Signature,
examples: &[Example],
command: &dyn Command,
engine_state: &EngineState,
stack: &mut Stack,
is_parser_keyword: bool,
) -> String {
let config = engine_state.get_config();
let doc_config = DocumentationConfig {
@ -23,14 +21,15 @@ pub fn get_full_help(
};
let stack = &mut stack.start_capture();
let signature = command.signature().update_from_command(command);
get_documentation(
sig,
examples,
&signature,
&command.examples(),
engine_state,
stack,
&doc_config,
is_parser_keyword,
command.is_keyword(),
)
}
@ -61,7 +60,6 @@ fn nu_highlight_string(code_string: &str, engine_state: &EngineState, stack: &mu
code_string.to_string()
}
#[allow(clippy::cognitive_complexity)]
fn get_documentation(
sig: &Signature,
examples: &[Example],

View File

@ -27,18 +27,8 @@ pub fn eval_call<D: DebugContext>(
let decl = engine_state.get_decl(call.decl_id);
if !decl.is_known_external() && call.named_iter().any(|(flag, _, _)| flag.item == "help") {
let mut signature = engine_state.get_signature(decl);
signature.usage = decl.usage().to_string();
signature.extra_usage = decl.extra_usage().to_string();
let full_help = get_full_help(
&signature,
&decl.examples(),
engine_state,
caller_stack,
decl.is_keyword(),
);
Ok(Value::string(full_help, call.head).into_pipeline_data())
let help = get_full_help(decl, engine_state, caller_stack);
Ok(Value::string(help, call.head).into_pipeline_data())
} else if let Some(block_id) = decl.block_id() {
let block = engine_state.get_block(block_id);