mirror of
https://github.com/nushell/nushell
synced 2024-11-10 15:14:14 +00:00
Change input/output types in help to a table (#9686)
# Description Updates `help` to more clearly show input/output types. Before: ![image](https://github.com/nushell/nushell/assets/547158/5f11ca5c-54a0-414d-b3de-1a8b4dd7fcbd) After: ![image](https://github.com/nushell/nushell/assets/547158/afc0eb1e-fad8-43b1-9382-c2a0d8e9334e) # User-Facing Changes See above # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
This commit is contained in:
parent
2fc9506bc7
commit
8c52b7a23a
3 changed files with 46 additions and 17 deletions
|
@ -20,13 +20,11 @@ fn help_commands_length() {
|
|||
#[test]
|
||||
fn help_shows_signature() {
|
||||
let actual = nu!("help str distance");
|
||||
assert!(actual
|
||||
.out
|
||||
.contains("<string> | str distance <string> -> <int>"));
|
||||
assert!(actual.out.contains("Input/output types"));
|
||||
|
||||
// don't show signature for parser keyword
|
||||
let actual = nu!("help alias");
|
||||
assert!(!actual.out.contains("Signatures"));
|
||||
assert!(!actual.out.contains("Input/output types"));
|
||||
}
|
||||
|
||||
#[ignore = "TODO: Need to decide how to do help messages of new aliases"]
|
||||
|
|
|
@ -3,7 +3,9 @@ use nu_protocol::{
|
|||
engine::{EngineState, Stack},
|
||||
Example, IntoPipelineData, PipelineData, Signature, Span, SyntaxShape, Value,
|
||||
};
|
||||
use std::fmt::Write;
|
||||
use std::{collections::HashMap, fmt::Write};
|
||||
|
||||
use crate::eval_call;
|
||||
|
||||
pub fn get_full_help(
|
||||
sig: &Signature,
|
||||
|
@ -129,17 +131,6 @@ fn get_documentation(
|
|||
}))
|
||||
}
|
||||
|
||||
if !is_parser_keyword && !sig.input_output_types.is_empty() {
|
||||
if sig.operates_on_cell_paths() {
|
||||
let _ = writeln!(
|
||||
long_desc,
|
||||
"\n{G}Signatures(Cell paths are supported){RESET}:\n{sig}"
|
||||
);
|
||||
} else {
|
||||
let _ = writeln!(long_desc, "\n{G}Signatures{RESET}:\n{sig}");
|
||||
}
|
||||
}
|
||||
|
||||
if !sig.required_positional.is_empty()
|
||||
|| !sig.optional_positional.is_empty()
|
||||
|| sig.rest_positional.is_some()
|
||||
|
@ -213,6 +204,46 @@ fn get_documentation(
|
|||
}
|
||||
}
|
||||
|
||||
if !is_parser_keyword && !sig.input_output_types.is_empty() {
|
||||
if let Some(decl_id) = engine_state.find_decl(b"table", &[]) {
|
||||
// FIXME: we may want to make this the span of the help command in the future
|
||||
let span = Span::unknown();
|
||||
let mut vals = vec![];
|
||||
for (input, output) in &sig.input_output_types {
|
||||
vals.push(Value::Record {
|
||||
cols: vec!["input".into(), "output".into()],
|
||||
vals: vec![
|
||||
Value::string(input.to_string(), span),
|
||||
Value::string(output.to_string(), span),
|
||||
],
|
||||
span,
|
||||
});
|
||||
}
|
||||
|
||||
let mut caller_stack = Stack::new();
|
||||
if let Ok(result) = eval_call(
|
||||
engine_state,
|
||||
&mut caller_stack,
|
||||
&Call {
|
||||
decl_id,
|
||||
head: span,
|
||||
arguments: vec![],
|
||||
redirect_stdout: true,
|
||||
redirect_stderr: true,
|
||||
parser_info: HashMap::new(),
|
||||
},
|
||||
PipelineData::Value(Value::List { vals, span }, None),
|
||||
) {
|
||||
if let Ok((str, ..)) = result.collect_string_strict(span) {
|
||||
let _ = writeln!(long_desc, "\n{G}Input/output types{RESET}:");
|
||||
for line in str.lines() {
|
||||
let _ = writeln!(long_desc, " {line}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !examples.is_empty() {
|
||||
let _ = write!(long_desc, "\n{G}Examples{RESET}:");
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ fn in_and_if_else() -> TestResult {
|
|||
#[test]
|
||||
fn help_works_with_missing_requirements() -> TestResult {
|
||||
// `each while` is part of the *extra* feature and adds 3 lines
|
||||
let expected_length = if cfg!(feature = "extra") { "66" } else { "63" };
|
||||
let expected_length = if cfg!(feature = "extra") { "70" } else { "67" };
|
||||
run_test(r#"each --help | lines | length"#, expected_length)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue