rename update to upsert to mirror what it really does (#4859)

* rename `update` to `upsert` to mirror what it really does

* change to latest reedline and nu-ansi-term
This commit is contained in:
Darren Schroeder
2022-03-16 19:13:34 -05:00
committed by GitHub
parent ca12f39db3
commit 6700fbeed7
14 changed files with 46 additions and 53 deletions

View File

@ -9,7 +9,7 @@ nu-path = { path = "../nu-path", version = "0.59.1" }
nu-parser = { path = "../nu-parser", version = "0.59.1" }
nu-protocol = { path = "../nu-protocol", version = "0.59.1" }
nu-utils = { path = "../nu-utils", version = "0.59.1" }
nu-ansi-term = "0.42.0"
nu-ansi-term = "0.45.0"
nu-color-config = { path = "../nu-color-config" }
@ -17,7 +17,7 @@ crossterm = "0.23.0"
crossterm_winapi = "0.9.0"
miette = { version = "4.1.0", features = ["fancy"] }
thiserror = "1.0.29"
reedline = { git = "https://github.com/nushell/reedline", branch = "main" }
reedline = "0.3.0"
log = "0.4"
is_executable = "1.0.1"

View File

@ -5,8 +5,7 @@ edition = "2021"
[dependencies]
nu-protocol = { path = "../nu-protocol", version = "0.59.1" }
# nu-ansi-term = { path = "../nu-ansi-term", version = "0.59.1" }
nu-ansi-term = "0.42.0"
nu-ansi-term = "0.45.0"
nu-json = { path = "../nu-json", version = "0.59.1" }
nu-table = { path = "../nu-table", version = "0.59.1" }

View File

@ -8,9 +8,6 @@ build = "build.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
# nu-ansi-term = {path = "../nu-ansi-term", version = "0.59.1" }
nu-ansi-term = "0.42.0"
nu-color-config = { path = "../nu-color-config", version = "0.59.1" }
nu-engine = { path = "../nu-engine", version = "0.59.1" }
nu-glob = { path = "../nu-glob", version = "0.59.1" }
@ -24,6 +21,7 @@ nu-table = { path = "../nu-table", version = "0.59.1" }
nu-term-grid = { path = "../nu-term-grid", version = "0.59.1" }
nu-test-support = { path = "../nu-test-support", version = "0.59.1" }
nu-utils = { path = "../nu-utils", version = "0.59.1" }
nu-ansi-term = "0.45.0"
# Potential dependencies for extras
base64 = "0.13.0"
@ -78,7 +76,7 @@ unicode-segmentation = "1.8.0"
url = "2.2.1"
uuid = { version = "0.8.2", features = ["v4"] }
which = { version = "4.2.2", optional = true }
reedline = { git = "https://github.com/nushell/reedline", branch = "main" }
reedline = "0.3.0"
zip = { version="0.5.9", optional = true }
[target.'cfg(unix)'.dependencies]

View File

@ -106,7 +106,7 @@ pub fn create_default_context(cwd: impl AsRef<Path>) -> EngineState {
SortBy,
Transpose,
Uniq,
Update,
Upsert,
UpdateCells,
Where,
Window,
@ -257,7 +257,7 @@ pub fn create_default_context(cwd: impl AsRef<Path>) -> EngineState {
ToCsv,
Touch,
Use,
Update,
Upsert,
Where,
ToUrl,
ToXml,

View File

@ -38,8 +38,8 @@ mod sort_by;
mod split_by;
mod transpose;
mod uniq;
mod update;
mod update_cells;
mod upsert;
mod where_;
mod window;
mod wrap;
@ -85,8 +85,8 @@ pub use sort_by::SortBy;
pub use split_by::SplitBy;
pub use transpose::Transpose;
pub use uniq::*;
pub use update::Update;
pub use update_cells::UpdateCells;
pub use upsert::Upsert;
pub use where_::Where;
pub use window::Window;
pub use wrap::Wrap;

View File

@ -7,19 +7,19 @@ use nu_protocol::{
};
#[derive(Clone)]
pub struct Update;
pub struct Upsert;
impl Command for Update {
impl Command for Upsert {
fn name(&self) -> &str {
"update"
"upsert"
}
fn signature(&self) -> Signature {
Signature::build("update")
Signature::build("upsert")
.required(
"field",
SyntaxShape::CellPath,
"the name of the column to update or create",
"the name of the column to update or insert",
)
.required(
"replacement value",
@ -30,7 +30,7 @@ impl Command for Update {
}
fn usage(&self) -> &str {
"Update an existing column to have a new value, or create a new column."
"Update an existing column to have a new value, or insert a new column."
}
fn run(
@ -40,31 +40,31 @@ impl Command for Update {
call: &Call,
input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
update(engine_state, stack, call, input)
upsert(engine_state, stack, call, input)
}
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Update a column value",
example: "echo {'name': 'nu', 'stars': 5} | update name 'Nushell'",
example: "echo {'name': 'nu', 'stars': 5} | upsert 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'",
description: "Insert a new column",
example: "echo {'name': 'nu', 'stars': 5} | upsert 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}",
example: "echo [[count fruit]; [1 'apple']] | upsert 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 {|a| $a.authors | str collect ','}",
example: "echo [[project, authors]; ['nu', ['Andrés', 'JT', 'Yehuda']]] | upsert 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()}),
}]
}
}
fn update(
fn upsert(
engine_state: &EngineState,
stack: &mut Stack,
call: &Call,
@ -148,6 +148,6 @@ mod test {
fn test_examples() {
use crate::test_examples;
test_examples(Update {})
test_examples(Upsert {})
}
}

View File

@ -81,7 +81,7 @@ On Windows, an extra 'prefix' column is added."#
},
Example {
description: "Replace a complex extension",
example: r"'C:\Users\viking\spam.tar.gz' | path parse -e tar.gz | update extension { 'txt' }",
example: r"'C:\Users\viking\spam.tar.gz' | path parse -e tar.gz | upsert extension { 'txt' }",
result: None,
},
Example {
@ -107,7 +107,7 @@ On Windows, an extra 'prefix' column is added."#
},
Example {
description: "Replace a complex extension",
example: r"'/home/viking/spam.tar.gz' | path parse -e tar.gz | update extension { 'txt' }",
example: r"'/home/viking/spam.tar.gz' | path parse -e tar.gz | upsert extension { 'txt' }",
result: None,
},
Example {

View File

@ -6,7 +6,7 @@ fn sets_the_column() {
cwd: "tests/fixtures/formats", pipeline(
r#"
open cargo_sample.toml
| update dev-dependencies.pretty_assertions "0.7.0"
| upsert dev-dependencies.pretty_assertions "0.7.0"
| get dev-dependencies.pretty_assertions
"#
));
@ -21,7 +21,7 @@ fn sets_the_column_from_a_block_run_output() {
cwd: "tests/fixtures/formats", pipeline(
r#"
open cargo_sample.toml
| update dev-dependencies.pretty_assertions { open cargo_sample.toml | get dev-dependencies.pretty_assertions | inc --minor }
| upsert dev-dependencies.pretty_assertions { open cargo_sample.toml | get dev-dependencies.pretty_assertions | inc --minor }
| get dev-dependencies.pretty_assertions
"#
));
@ -35,7 +35,7 @@ fn sets_the_column_from_a_block_full_stream_output() {
cwd: "tests/fixtures/formats", pipeline(
r#"
wrap content
| update content { open --raw cargo_sample.toml | lines | first 5 }
| upsert content { open --raw cargo_sample.toml | lines | first 5 }
| get content.1
| str contains "nu"
"#
@ -50,7 +50,7 @@ fn sets_the_column_from_a_subexpression() {
cwd: "tests/fixtures/formats", pipeline(
r#"
wrap content
| update content (open --raw cargo_sample.toml | lines | first 5)
| upsert content (open --raw cargo_sample.toml | lines | first 5)
| get content.1
| str contains "nu"
"#

View File

@ -36,7 +36,7 @@ fn zips_two_tables() {
[ jt, 20]
]);
let actual = ($contributors | update commits {{ |i| ($i.commits + 10) }});
let actual = ($contributors | upsert commits {{ |i| ($i.commits + 10) }});
expect $actual --to-eq [[name, commits]; [andres, 20] [jt, 30]]
"#,

View File

@ -16,8 +16,7 @@ name = "nu_pretty_hex"
path = "src/main.rs"
[dependencies]
#nu-ansi-term = {path = "../nu-ansi-term", version = "0.59.1" }
nu-ansi-term = "0.42.0"
nu-ansi-term = "0.45.0"
rand = "0.8.3"

View File

@ -12,8 +12,7 @@ name = "table"
path = "src/main.rs"
[dependencies]
# nu-ansi-term = { path = "../nu-ansi-term", version = "0.59.1" }
nu-ansi-term = "0.42.0"
nu-ansi-term = "0.45.0"
nu-protocol = { path = "../nu-protocol", version = "0.59.1" }
regex = "1.4"
unicode-width = "0.1.8"