Start support for commandline args to nu itself (#851)

* cmdline args wip

* WIP

* redirect working

* Add help and examples

* Only show flags in signature of more than help
This commit is contained in:
JT
2022-01-26 09:42:39 -05:00
committed by GitHub
parent 285f65ba34
commit 8ee619954d
9 changed files with 307 additions and 97 deletions

View File

@ -186,6 +186,10 @@ pub fn get_documentation(
long_desc.push('\n');
}
if !sig.named.is_empty() {
long_desc.push_str(&get_flags_section(sig))
}
if !sig.required_positional.is_empty()
|| !sig.optional_positional.is_empty()
|| sig.rest_positional.is_some()
@ -205,13 +209,11 @@ pub fn get_documentation(
long_desc.push_str(&format!(" ...args: {}\n", rest_positional.desc));
}
}
if !sig.named.is_empty() {
long_desc.push_str(&get_flags_section(sig))
}
if !examples.is_empty() {
long_desc.push_str("\nExamples:");
}
for example in examples {
long_desc.push('\n');
long_desc.push_str(" ");
@ -222,7 +224,7 @@ pub fn get_documentation(
} else if let Some(highlighter) = engine_state.find_decl(b"nu-highlight") {
let decl = engine_state.get_decl(highlighter);
if let Ok(output) = decl.run(
match decl.run(
engine_state,
stack,
&Call::new(),
@ -232,16 +234,23 @@ pub fn get_documentation(
}
.into_pipeline_data(),
) {
let result = output.into_value(Span { start: 0, end: 0 });
match result.as_string() {
Ok(s) => {
long_desc.push_str(&format!("\n > {}\n", s));
}
_ => {
long_desc.push_str(&format!("\n > {}\n", example.example));
Ok(output) => {
let result = output.into_value(Span { start: 0, end: 0 });
match result.as_string() {
Ok(s) => {
long_desc.push_str(&format!("\n > {}\n", s));
}
_ => {
long_desc.push_str(&format!("\n > {}\n", example.example));
}
}
}
Err(_) => {
long_desc.push_str(&format!("\n > {}\n", example.example));
}
}
} else {
long_desc.push_str(&format!("\n > {}\n", example.example));
}
}