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

@ -191,13 +191,7 @@ pub(crate) fn parse_commandline_args(
let help = call.has_flag(engine_state, &mut stack, "help")?;
if help {
let full_help = get_full_help(
&Nu.signature(),
&Nu.examples(),
engine_state,
&mut stack,
true,
);
let full_help = get_full_help(&Nu, engine_state, &mut stack);
let _ = std::panic::catch_unwind(move || stdout_write_all_and_flush(full_help));
@ -245,13 +239,7 @@ pub(crate) fn parse_commandline_args(
}
// Just give the help and exit if the above fails
let full_help = get_full_help(
&Nu.signature(),
&Nu.examples(),
engine_state,
&mut stack,
true,
);
let full_help = get_full_help(&Nu, engine_state, &mut stack);
print!("{full_help}");
std::process::exit(1);
}
@ -452,11 +440,7 @@ impl Command for Nu {
call: &Call,
_input: PipelineData,
) -> Result<PipelineData, ShellError> {
Ok(Value::string(
get_full_help(&Nu.signature(), &Nu.examples(), engine_state, stack, true),
call.head,
)
.into_pipeline_data())
Ok(Value::string(get_full_help(self, engine_state, stack), call.head).into_pipeline_data())
}
fn examples(&self) -> Vec<nu_protocol::Example> {