mirror of
https://github.com/nushell/nushell.git
synced 2025-04-26 06:08:21 +02:00
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:
parent
10d805c1fa
commit
cb5d997adf
@ -19,7 +19,7 @@ impl Command for Update {
|
|||||||
.required(
|
.required(
|
||||||
"field",
|
"field",
|
||||||
SyntaxShape::CellPath,
|
SyntaxShape::CellPath,
|
||||||
"the name of the column to update",
|
"the name of the column to update or create",
|
||||||
)
|
)
|
||||||
.required(
|
.required(
|
||||||
"replacement value",
|
"replacement value",
|
||||||
@ -30,7 +30,7 @@ impl Command for Update {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
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(
|
fn run(
|
||||||
@ -48,13 +48,17 @@ impl Command for Update {
|
|||||||
description: "Update a column value",
|
description: "Update a column value",
|
||||||
example: "echo {'name': 'nu', 'stars': 5} | update name 'Nushell'",
|
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()}),
|
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 {
|
}, Example {
|
||||||
description: "Use in block form for more involved updating logic",
|
description: "Use in block form for more involved updating logic",
|
||||||
example: "echo [[count fruit]; [1 'apple']] | update count {|f| $f.count + 1}",
|
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()}),
|
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 {
|
}, Example {
|
||||||
description: "Use in block form for more involved updating logic",
|
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()}),
|
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 {})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user