Change update help+examples for creating new columns (#4849)

* Change update help/examples for creating new column

* Enable example tests for update command
This commit is contained in:
Reilly Wood 2022-03-14 13:32:33 -07:00 committed by GitHub
parent 10d805c1fa
commit cb5d997adf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,7 +19,7 @@ impl Command for Update {
.required(
"field",
SyntaxShape::CellPath,
"the name of the column to update",
"the name of the column to update or create",
)
.required(
"replacement value",
@ -30,7 +30,7 @@ impl Command for Update {
}
fn usage(&self) -> &str {
"Update an existing column to have a new value."
"Update an existing column to have a new value, or create a new column."
}
fn run(
@ -48,13 +48,17 @@ impl Command for Update {
description: "Update a column value",
example: "echo {'name': 'nu', 'stars': 5} | update name 'Nushell'",
result: Some(Value::Record { cols: vec!["name".into(), "stars".into()], vals: vec![Value::test_string("Nushell"), Value::test_int(5)], span: Span::test_data()}),
}, Example {
description: "Add a new column",
example: "echo {'name': 'nu', 'stars': 5} | update language 'Rust'",
result: Some(Value::Record { cols: vec!["name".into(), "stars".into(), "language".into()], vals: vec![Value::test_string("nu"), Value::test_int(5), Value::test_string("Rust")], span: Span::test_data()}),
}, Example {
description: "Use in block form for more involved updating logic",
example: "echo [[count fruit]; [1 'apple']] | update count {|f| $f.count + 1}",
result: Some(Value::List { vals: vec![Value::Record { cols: vec!["count".into(), "fruit".into()], vals: vec![Value::test_int(2), Value::test_string("apple")], span: Span::test_data()}], span: Span::test_data()}),
}, Example {
description: "Use in block form for more involved updating logic",
example: "echo [[project, authors]; ['nu', ['Andrés', 'JT', 'Yehuda']]] | update authors { get authors | str collect ',' }",
example: "echo [[project, authors]; ['nu', ['Andrés', 'JT', 'Yehuda']]] | update authors {|a| $a.authors | str collect ','}",
result: Some(Value::List { vals: vec![Value::Record { cols: vec!["project".into(), "authors".into()], vals: vec![Value::test_string("nu"), Value::test_string("Andrés,JT,Yehuda")], span: Span::test_data()}], span: Span::test_data()}),
}]
}
@ -135,3 +139,15 @@ fn update(
)
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_examples() {
use crate::test_examples;
test_examples(Update {})
}
}