From f2c2e9d24d024c5397e04347e8ce2c93724bbdfa Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Wed, 19 Jun 2024 19:37:26 -0500 Subject: [PATCH] add collapse example --- crates/nu-command/src/viewers/table.rs | 5 +++- crates/nu-engine/src/documentation.rs | 33 ++++++++++++++++++-------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/crates/nu-command/src/viewers/table.rs b/crates/nu-command/src/viewers/table.rs index 65e0644ac0..075a4e31c4 100644 --- a/crates/nu-command/src/viewers/table.rs +++ b/crates/nu-command/src/viewers/table.rs @@ -187,7 +187,10 @@ impl Command for Table { }), Value::test_record(record! { "a" => Value::test_int(3), - "b" => Value::test_int(4), + "b" => Value::test_list(vec![ + Value::test_int(4), + Value::test_int(4), + ]) }), ])), }, diff --git a/crates/nu-engine/src/documentation.rs b/crates/nu-engine/src/documentation.rs index 59fcbe6037..43952b8136 100644 --- a/crates/nu-engine/src/documentation.rs +++ b/crates/nu-engine/src/documentation.rs @@ -296,15 +296,28 @@ fn get_documentation( } if let Some(result) = &example.result { - let mut table_expand_call = Call::new(Span::unknown()); - table_expand_call.add_named(( - Spanned { - item: "expand".to_string(), - span: Span::unknown(), - }, - None, - None, - )); + let mut table_call = Call::new(Span::unknown()); + if *&example.example.ends_with("--collapse") { + // collapse the result + table_call.add_named(( + Spanned { + item: "collapse".to_string(), + span: Span::unknown(), + }, + None, + None, + )) + } else { + // expand the result + table_call.add_named(( + Spanned { + item: "expand".to_string(), + span: Span::unknown(), + }, + None, + None, + )) + } let table = engine_state .find_decl("table".as_bytes(), &[]) .and_then(|decl_id| { @@ -313,7 +326,7 @@ fn get_documentation( .run( engine_state, stack, - &table_expand_call, + &table_call, PipelineData::Value(result.clone(), None), ) .ok()