mirror of
https://github.com/nushell/nushell.git
synced 2025-04-30 08:04:25 +02:00
Cut out a function to generate a pharase in the Flags section. (#1930)
This commit is contained in:
parent
b6f9d0ca58
commit
5dd346094e
@ -182,8 +182,8 @@ pub fn get_help(cmd: &dyn WholeStreamCommand, registry: &CommandRegistry) -> Str
|
|||||||
|
|
||||||
if !signature.positional.is_empty() || signature.rest_positional.is_some() {
|
if !signature.positional.is_empty() || signature.rest_positional.is_some() {
|
||||||
long_desc.push_str("\nParameters:\n");
|
long_desc.push_str("\nParameters:\n");
|
||||||
for positional in signature.positional {
|
for positional in &signature.positional {
|
||||||
match positional.0 {
|
match &positional.0 {
|
||||||
PositionalType::Mandatory(name, _m) => {
|
PositionalType::Mandatory(name, _m) => {
|
||||||
long_desc.push_str(&format!(" <{}> {}\n", name, positional.1));
|
long_desc.push_str(&format!(" <{}> {}\n", name, positional.1));
|
||||||
}
|
}
|
||||||
@ -193,13 +193,37 @@ pub fn get_help(cmd: &dyn WholeStreamCommand, registry: &CommandRegistry) -> Str
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(rest_positional) = signature.rest_positional {
|
if let Some(rest_positional) = &signature.rest_positional {
|
||||||
long_desc.push_str(&format!(" ...args: {}\n", rest_positional.1));
|
long_desc.push_str(&format!(" ...args: {}\n", rest_positional.1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !signature.named.is_empty() {
|
if !signature.named.is_empty() {
|
||||||
|
long_desc.push_str(&get_flags_section(&signature))
|
||||||
|
}
|
||||||
|
|
||||||
|
let palette = crate::shell::palette::DefaultPalette {};
|
||||||
|
let examples = cmd.examples();
|
||||||
|
if !examples.is_empty() {
|
||||||
|
long_desc.push_str("\nExamples:");
|
||||||
|
}
|
||||||
|
for example in examples {
|
||||||
|
long_desc.push_str("\n");
|
||||||
|
long_desc.push_str(" ");
|
||||||
|
long_desc.push_str(example.description);
|
||||||
|
let colored_example =
|
||||||
|
crate::shell::helper::Painter::paint_string(example.example, registry, &palette);
|
||||||
|
long_desc.push_str(&format!("\n > {}\n", colored_example));
|
||||||
|
}
|
||||||
|
|
||||||
|
long_desc.push_str("\n");
|
||||||
|
|
||||||
|
long_desc
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_flags_section(signature: &Signature) -> String {
|
||||||
|
let mut long_desc = String::new();
|
||||||
long_desc.push_str("\nFlags:\n");
|
long_desc.push_str("\nFlags:\n");
|
||||||
for (flag, ty) in signature.named {
|
for (flag, ty) in &signature.named {
|
||||||
let msg = match ty.0 {
|
let msg = match ty.0 {
|
||||||
NamedType::Switch(s) => {
|
NamedType::Switch(s) => {
|
||||||
if let Some(c) = s {
|
if let Some(c) = s {
|
||||||
@ -262,24 +286,6 @@ pub fn get_help(cmd: &dyn WholeStreamCommand, registry: &CommandRegistry) -> Str
|
|||||||
};
|
};
|
||||||
long_desc.push_str(&msg);
|
long_desc.push_str(&msg);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let palette = crate::shell::palette::DefaultPalette {};
|
|
||||||
let examples = cmd.examples();
|
|
||||||
if !examples.is_empty() {
|
|
||||||
long_desc.push_str("\nExamples:");
|
|
||||||
}
|
|
||||||
for example in examples {
|
|
||||||
long_desc.push_str("\n");
|
|
||||||
long_desc.push_str(" ");
|
|
||||||
long_desc.push_str(example.description);
|
|
||||||
let colored_example =
|
|
||||||
crate::shell::helper::Painter::paint_string(example.example, registry, &palette);
|
|
||||||
long_desc.push_str(&format!("\n > {}\n", colored_example));
|
|
||||||
}
|
|
||||||
|
|
||||||
long_desc.push_str("\n");
|
|
||||||
|
|
||||||
long_desc
|
long_desc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user