From ed82f9ee18f382557135336459b1d098e0406d39 Mon Sep 17 00:00:00 2001 From: NotTheDr01ds <32344964+NotTheDr01ds@users.noreply.github.com> Date: Fri, 2 Aug 2024 15:23:25 -0400 Subject: [PATCH] Clarify `default` command help (#13519) # Description Updates `default` command description to be more clear and adds an example for a missing values in a list-of-records. # User-Facing Changes Help/doc only # Tests + Formatting - :green_circle: `toolkit fmt` - :green_circle: `toolkit clippy` - :green_circle: `toolkit test` - :green_circle: `toolkit test stdlib` # After Submitting - Update `nothing` doc in Book to reference `default` per https://github.com/nushell/nushell.github.io/issues/1073 - This was a bit of a rabbit trail on the path to that update. ;-) --------- Co-authored-by: Stefan Holderbach --- crates/nu-command/src/filters/default.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/nu-command/src/filters/default.rs b/crates/nu-command/src/filters/default.rs index 9b08ce6331..3f7f93c3f6 100644 --- a/crates/nu-command/src/filters/default.rs +++ b/crates/nu-command/src/filters/default.rs @@ -27,7 +27,7 @@ impl Command for Default { } fn usage(&self) -> &str { - "Sets a default row's column if missing." + "Sets a default value if a row's column is missing or null." } fn run( @@ -66,6 +66,20 @@ impl Command for Default { Span::test_data(), )), }, + Example { + description: r#"Replace the missing value in the "a" column of a list"#, + example: "[{a:1 b:2} {b:1}] | default 'N/A' a", + result: Some(Value::test_list(vec![ + Value::test_record(record! { + "a" => Value::test_int(1), + "b" => Value::test_int(2), + }), + Value::test_record(record! { + "a" => Value::test_string("N/A"), + "b" => Value::test_int(1), + }), + ])), + }, ] } }