mirror of
https://github.com/nushell/nushell
synced 2024-12-25 12:33:17 +00:00
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:
parent
ca12f39db3
commit
6700fbeed7
14 changed files with 46 additions and 53 deletions
24
Cargo.lock
generated
24
Cargo.lock
generated
|
@ -1422,12 +1422,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.3.3"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c"
|
||||
dependencies = [
|
||||
"unicode-segmentation",
|
||||
]
|
||||
checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
|
@ -2185,9 +2182,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "nu-ansi-term"
|
||||
version = "0.42.0"
|
||||
version = "0.45.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b8afa9b5ba9e7ea9898e119244372cac911bea31ee7a5de42f51bbc36dc66318"
|
||||
checksum = "280affd8593c03f90633b7305cee7a3b55ddab9fbad95041a39bda689f7b64f7"
|
||||
dependencies = [
|
||||
"overload",
|
||||
"winapi",
|
||||
|
@ -3464,8 +3461,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "reedline"
|
||||
version = "0.2.0"
|
||||
source = "git+https://github.com/nushell/reedline?branch=main#4e5a20d127d84f4722e1d39d1852ccb42aa973f6"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "33ba0eb9271feb2de4b1516d651c96d80c892df24388e2711ef2495acc6ed9ce"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"crossterm",
|
||||
|
@ -4090,15 +4088,15 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "strum"
|
||||
version = "0.23.0"
|
||||
version = "0.24.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cae14b91c7d11c9a851d3fbc80a963198998c2a64eec840477fa92d8ce9b70bb"
|
||||
checksum = "e96acfc1b70604b8b2f1ffa4c57e59176c7dbb05d556c71ecd2f5498a1dee7f8"
|
||||
|
||||
[[package]]
|
||||
name = "strum_macros"
|
||||
version = "0.23.1"
|
||||
version = "0.24.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5bb0dc7ee9c15cea6199cde9a127fa16a4c5819af85395457ad72d68edc85a38"
|
||||
checksum = "6878079b17446e4d3eba6192bb0a2950d5b14f0ed8424b852310e5a94345d0ef"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
|
|
|
@ -37,7 +37,7 @@ crossterm_winapi = "0.9.0"
|
|||
ctrlc = "3.2.1"
|
||||
log = "0.4"
|
||||
miette = "4.1.0"
|
||||
nu-ansi-term = "0.42.0"
|
||||
nu-ansi-term = "0.45.0"
|
||||
nu-cli = { path="./crates/nu-cli", version = "0.59.1" }
|
||||
nu-color-config = { path = "./crates/nu-color-config", version = "0.59.1" }
|
||||
nu-command = { path="./crates/nu-command", version = "0.59.1" }
|
||||
|
@ -54,7 +54,7 @@ nu-term-grid = { path = "./crates/nu-term-grid", version = "0.59.1" }
|
|||
nu-utils = { path = "./crates/nu-utils", version = "0.59.1" }
|
||||
pretty_env_logger = "0.4.0"
|
||||
rayon = "1.5.1"
|
||||
reedline = { git = "https://github.com/nushell/reedline", branch = "main" }
|
||||
reedline = "0.3.0"
|
||||
is_executable = "1.0.1"
|
||||
|
||||
[dev-dependencies]
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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" }
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {})
|
||||
}
|
||||
}
|
|
@ -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 {
|
||||
|
|
|
@ -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"
|
||||
"#
|
||||
|
|
|
@ -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]]
|
||||
"#,
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -216,7 +216,7 @@ fn select_2() -> TestResult {
|
|||
|
||||
#[test]
|
||||
fn update_will_insert() -> TestResult {
|
||||
run_test(r#"{} | update a b | get a"#, "b")
|
||||
run_test(r#"{} | upsert a b | get a"#, "b")
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in a new issue