add signature information when get help on one command (#7079)

* add signature information when help on one command

* tell user that one command support operated on cell paths

Also, make type output to be more friendly, like `record<>` should just be `record`

And the same to `table<>`, which should be `table`

* simplify code

* don't show signatures for parser keyword

* update comment

* output arg syntax shape as type, so it's the same as describe command

* fix string when no positional args

* update signature body

* update

* add help signature test

* fix arg output format for composed data type like list or record

* fix clippy

* add comment
This commit is contained in:
WindSoilder
2022-11-20 21:22:42 +08:00
committed by GitHub
parent a896892ac9
commit d01ccd5a54
29 changed files with 258 additions and 55 deletions

View File

@ -10,6 +10,7 @@ pub fn get_full_help(
examples: &[Example],
engine_state: &EngineState,
stack: &mut Stack,
is_parser_keyword: bool,
) -> String {
let config = engine_state.get_config();
let doc_config = DocumentationConfig {
@ -17,7 +18,14 @@ pub fn get_full_help(
no_color: !config.use_ansi_coloring,
brief: false,
};
get_documentation(sig, examples, engine_state, stack, &doc_config)
get_documentation(
sig,
examples,
engine_state,
stack,
&doc_config,
is_parser_keyword,
)
}
#[derive(Default)]
@ -34,6 +42,7 @@ fn get_documentation(
engine_state: &EngineState,
stack: &mut Stack,
config: &DocumentationConfig,
is_parser_keyword: bool,
) -> String {
// Create ansi colors
const G: &str = "\x1b[32m"; // green
@ -89,6 +98,18 @@ fn get_documentation(
long_desc.push_str(&get_flags_section(sig))
}
if !is_parser_keyword && !sig.input_output_types.is_empty() {
if sig.operates_on_cell_paths() {
let _ = writeln!(
long_desc,
"\n{}Signatures(Cell paths are supported){}:\n{}",
G, RESET, sig
);
} else {
let _ = writeln!(long_desc, "\n{}Signatures{}:\n{}", G, RESET, sig);
}
}
if !sig.required_positional.is_empty()
|| !sig.optional_positional.is_empty()
|| sig.rest_positional.is_some()