mirror of
https://github.com/nushell/nushell.git
synced 2025-02-22 13:31:34 +01:00
Rename add to insert
This commit is contained in:
parent
6e91c96dd7
commit
e92d4b2ccb
@ -130,8 +130,8 @@ name = "nu_plugin_embed"
|
|||||||
path = "src/plugins/embed.rs"
|
path = "src/plugins/embed.rs"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "nu_plugin_add"
|
name = "nu_plugin_insert"
|
||||||
path = "src/plugins/add.rs"
|
path = "src/plugins/insert.rs"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "nu_plugin_edit"
|
name = "nu_plugin_edit"
|
||||||
|
@ -6,19 +6,19 @@ use nu::{
|
|||||||
|
|
||||||
pub type ColumnPath = Vec<Tagged<String>>;
|
pub type ColumnPath = Vec<Tagged<String>>;
|
||||||
|
|
||||||
struct Add {
|
struct Insert {
|
||||||
field: Option<ColumnPath>,
|
field: Option<ColumnPath>,
|
||||||
value: Option<Value>,
|
value: Option<Value>,
|
||||||
}
|
}
|
||||||
impl Add {
|
impl Insert {
|
||||||
fn new() -> Add {
|
fn new() -> Insert {
|
||||||
Add {
|
Insert {
|
||||||
field: None,
|
field: None,
|
||||||
value: None,
|
value: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add(&self, value: Tagged<Value>) -> Result<Tagged<Value>, ShellError> {
|
fn insert(&self, value: Tagged<Value>) -> Result<Tagged<Value>, ShellError> {
|
||||||
let value_tag = value.tag();
|
let value_tag = value.tag();
|
||||||
match (value.item, self.value.clone()) {
|
match (value.item, self.value.clone()) {
|
||||||
(obj @ Value::Row(_), Some(v)) => match &self.field {
|
(obj @ Value::Row(_), Some(v)) => match &self.field {
|
||||||
@ -50,11 +50,15 @@ impl Add {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Plugin for Add {
|
impl Plugin for Insert {
|
||||||
fn config(&mut self) -> Result<Signature, ShellError> {
|
fn config(&mut self) -> Result<Signature, ShellError> {
|
||||||
Ok(Signature::build("add")
|
Ok(Signature::build("insert")
|
||||||
.desc("Add a new column to the table.")
|
.desc("Insert a new column to the table.")
|
||||||
.required("column", SyntaxShape::ColumnPath, "the column name to add")
|
.required(
|
||||||
|
"column",
|
||||||
|
SyntaxShape::ColumnPath,
|
||||||
|
"the column name to insert",
|
||||||
|
)
|
||||||
.required(
|
.required(
|
||||||
"value",
|
"value",
|
||||||
SyntaxShape::String,
|
SyntaxShape::String,
|
||||||
@ -86,10 +90,10 @@ impl Plugin for Add {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn filter(&mut self, input: Tagged<Value>) -> Result<Vec<ReturnValue>, ShellError> {
|
fn filter(&mut self, input: Tagged<Value>) -> Result<Vec<ReturnValue>, ShellError> {
|
||||||
Ok(vec![ReturnSuccess::value(self.add(input)?)])
|
Ok(vec![ReturnSuccess::value(self.insert(input)?)])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
serve_plugin(&mut Add::new());
|
serve_plugin(&mut Insert::new());
|
||||||
}
|
}
|
@ -42,12 +42,12 @@ fn external_has_correct_quotes() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn add_plugin() {
|
fn insert_plugin() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: "tests/fixtures/formats", h::pipeline(
|
cwd: "tests/fixtures/formats", h::pipeline(
|
||||||
r#"
|
r#"
|
||||||
open cargo_sample.toml
|
open cargo_sample.toml
|
||||||
| add dev-dependencies.newdep "1"
|
| insert dev-dependencies.newdep "1"
|
||||||
| get dev-dependencies.newdep
|
| get dev-dependencies.newdep
|
||||||
| echo $it
|
| echo $it
|
||||||
"#
|
"#
|
||||||
|
Loading…
Reference in New Issue
Block a user