Rework help generation internals (#13531)

Reworking some of the sprawling code we use to generate the `help cmd`
or `cmd --help` output.

This touches mainly the rendering and not the gathering of the necessary
data (see open bugs under
[label:help-system](https://github.com/nushell/nushell/issues?q=sort%3Aupdated-desc+is%3Aopen+label%3Ahelp-system))

Fixes #9076 
Fixes the syntax shape output on flags to be consistent.

## Example
```nushell
def test [
  positional: int,
  documented: float, # this has documentation
  default = 50,
  optional?,
  --a = "bla",
  --bla (-b) = "bla", # named with default
] {}
```

### before

![grafik](https://github.com/user-attachments/assets/1867984f-1289-4ad0-bdf5-c49ec56dfddb)


### after


![grafik](https://github.com/user-attachments/assets/8fca526f-d878-4d52-b970-fc41c7e8859c)
This commit is contained in:
Stefan Holderbach
2024-08-05 22:44:24 +02:00
committed by GitHub
parent 1c37f4b958
commit 9172b22985
3 changed files with 244 additions and 304 deletions

View File

@ -9,7 +9,7 @@ use std::{
thread,
};
use nu_engine::documentation::get_flags_section;
use nu_engine::documentation::{get_flags_section, HelpStyle};
use nu_plugin_core::{
ClientCommunicationIo, CommunicationMode, InterfaceManager, PluginEncoder, PluginRead,
PluginWrite,
@ -657,6 +657,7 @@ fn print_help(plugin: &impl Plugin, encoder: impl PluginEncoder) {
println!("Encoder: {}", encoder.name());
let mut help = String::new();
let help_style = HelpStyle::default();
plugin.commands().into_iter().for_each(|command| {
let signature = command.signature();
@ -670,7 +671,7 @@ fn print_help(plugin: &impl Plugin, encoder: impl PluginEncoder) {
}
})
.and_then(|_| {
let flags = get_flags_section(None, None, &signature, |v| format!("{:#?}", v));
let flags = get_flags_section(&signature, &help_style, |v| format!("{:#?}", v));
write!(help, "{flags}")
})
.and_then(|_| writeln!(help, "\nParameters:"))