summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNotTheDr01ds <32344964+NotTheDr01ds@users.noreply.github.com>2024-06-19 21:12:25 -0400
committerGitHub <noreply@github.com>2024-06-19 20:12:25 -0500
commit44aa0a2de41295851a035fde3c3d5b7a2e3e7030 (patch)
treec55ddaa7d1a9cc98a6baa78a1454fecc3ab7aa16
parent12991cd36feedaac0ccb86be61e78a8ca4ffd261 (diff)
Table help rendering (#13182)
# Description Mostly fixes #13149 with much of the credit to @fdncred. This PR runs `table --expand` against `help` example results. This is essentially the same fix that #13146 was for `std help`. It also changes the shape of the result for the `table --expand` example, as it was hardcoded wrong. ~Still needed is a fix for the `table --collapse` example.~ Note that this is also still a bug in `std help` that I didn't noticed before. # User-Facing Changes Certain tables are now rendered correctly in the help examples for: * `table` * `zip` * `flatten` * And almost certainly others # Tests + Formatting - :green_circle: `toolkit fmt` - :green_circle: `toolkit clippy` - :green_circle: `toolkit test` - :green_circle: `toolkit test stdlib` # After Submitting --------- Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
-rw-r--r--crates/nu-command/src/viewers/table.rs10
-rw-r--r--crates/nu-engine/src/documentation.rs26
2 files changed, 32 insertions, 4 deletions
diff --git a/crates/nu-command/src/viewers/table.rs b/crates/nu-command/src/viewers/table.rs
index 2fe931982..075a4e31c 100644
--- a/crates/nu-command/src/viewers/table.rs
+++ b/crates/nu-command/src/viewers/table.rs
@@ -170,7 +170,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),
+ ])
}),
])),
},
@@ -184,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 94cef3298..a7d495003 100644
--- a/crates/nu-engine/src/documentation.rs
+++ b/crates/nu-engine/src/documentation.rs
@@ -3,7 +3,7 @@ use nu_protocol::{
ast::{Argument, Call, Expr, Expression, RecordItem},
debugger::WithoutDebug,
engine::{Command, EngineState, Stack, UNKNOWN_SPAN_ID},
- record, Category, Example, IntoPipelineData, PipelineData, Signature, Span, SpanId,
+ record, Category, Example, IntoPipelineData, PipelineData, Signature, Span, SpanId, Spanned,
SyntaxShape, Type, Value,
};
use std::{collections::HashMap, fmt::Write};
@@ -296,6 +296,28 @@ fn get_documentation(
}
if let Some(result) = &example.result {
+ 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| {
@@ -304,7 +326,7 @@ fn get_documentation(
.run(
engine_state,
stack,
- &Call::new(Span::new(0, 0)),
+ &table_call,
PipelineData::Value(result.clone(), None),
)
.ok()