From c2118e7505d779103bf6f6c845ea86f8a1cd70c0 Mon Sep 17 00:00:00 2001 From: JT <547158+jntrnr@users.noreply.github.com> Date: Wed, 9 Feb 2022 21:24:29 -0500 Subject: [PATCH] Fix help flag (#4398) * Match 'help command' to 'command --help' * Fix tests --- crates/nu-command/tests/format_conversions/html.rs | 6 +++--- crates/nu-engine/src/eval.rs | 11 +++++------ src/tests/test_engine.rs | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/crates/nu-command/tests/format_conversions/html.rs b/crates/nu-command/tests/format_conversions/html.rs index 555ac1abb3..f670ee087b 100644 --- a/crates/nu-command/tests/format_conversions/html.rs +++ b/crates/nu-command/tests/format_conversions/html.rs @@ -56,7 +56,7 @@ fn test_cd_html_color_flag_dark_false() { ); assert_eq!( actual.out, - r"Usage:
> cd (path)

Flags:
-h, --help
Display this help message

Parameters:
(optional) path: the path to change to

" + r"Change directory.

Usage:
> cd (path)

Flags:
-h, --help
Display this help message

Parameters:
(optional) path: the path to change to

" ); } @@ -71,7 +71,7 @@ fn test_no_color_flag() { ); assert_eq!( actual.out, - r"Usage:
> cd (path)

Flags:
-h, --help
Display this help message

Parameters:
(optional) path: the path to change to

" + r"Change directory.

Usage:
> cd (path)

Flags:
-h, --help
Display this help message

Parameters:
(optional) path: the path to change to

" ); } @@ -86,6 +86,6 @@ fn test_html_color_where_flag_dark_false() { ); assert_eq!( actual.out, - r"Usage:
> where <cond>

Flags:
-h, --help
Display this help message

Parameters:
cond: condition

" + r"Filter values based on a condition.

Usage:
> where <cond>

Flags:
-h, --help
Display this help message

Parameters:
cond: condition

" ); } diff --git a/crates/nu-engine/src/eval.rs b/crates/nu-engine/src/eval.rs index 68d0bd5abf..33a629348e 100644 --- a/crates/nu-engine/src/eval.rs +++ b/crates/nu-engine/src/eval.rs @@ -33,12 +33,11 @@ fn eval_call( let decl = engine_state.get_decl(call.decl_id); if call.named.iter().any(|(flag, _)| flag.item == "help") { - let full_help = get_full_help( - &decl.signature(), - &decl.examples(), - engine_state, - caller_stack, - ); + let mut signature = decl.signature(); + signature.usage = decl.usage().to_string(); + signature.extra_usage = decl.extra_usage().to_string(); + + let full_help = get_full_help(&signature, &decl.examples(), engine_state, caller_stack); Ok(Value::String { val: full_help, span: call.head, diff --git a/src/tests/test_engine.rs b/src/tests/test_engine.rs index a3fec1c106..43737b7e8c 100644 --- a/src/tests/test_engine.rs +++ b/src/tests/test_engine.rs @@ -72,7 +72,7 @@ fn in_variable_6() -> TestResult { #[test] fn help_works_with_missing_requirements() -> TestResult { - run_test(r#"each --help | lines | length"#, "20") + run_test(r#"each --help | lines | length"#, "22") } #[test]