mirror of
https://github.com/nushell/nushell
synced 2024-11-10 15:14:14 +00:00
make reject support list input directly (#11024)
# Description Fixes: #10895 It's because `reject` and `select` command can't handle list of CellPath input directly. After this pr, the following should be ok: ```nushell ❯ [{'a': 1, 'b': 2, 'c': 3}, {'a': 1, 'b': 2, 'c': 3}] | reject ['a', 'b'] ╭───┬───╮ │ # │ c │ ├───┼───┤ │ 0 │ 3 │ │ 1 │ 3 │ ╰───┴───╯ ❯ [{'a': 1, 'b': 2, 'c': 3}, {'a': 1, 'b': 2, 'c': 3}] | select ['a', 'b'] ╭───┬───┬───╮ │ # │ a │ b │ ├───┼───┼───┤ │ 0 │ 1 │ 2 │ │ 1 │ 1 │ 2 │ ╰───┴───┴───╯ ```
This commit is contained in:
parent
588a078872
commit
6bee80dcd7
2 changed files with 22 additions and 0 deletions
|
@ -89,6 +89,7 @@ impl Command for Reject {
|
|||
};
|
||||
new_columns.push(cv.clone());
|
||||
}
|
||||
Value::CellPath { val, .. } => new_columns.push(val),
|
||||
y => {
|
||||
return Err(ShellError::CantConvert {
|
||||
to_type: "cell path".into(),
|
||||
|
@ -189,6 +190,15 @@ impl Command for Reject {
|
|||
example: "let cols = [size type];[[name type size]; [Cargo.toml toml 1kb] [Cargo.lock toml 2kb]] | reject $cols",
|
||||
result: None
|
||||
},
|
||||
Example {
|
||||
description: "Reject columns by a list of columns directly",
|
||||
example: r#"[[name type size]; [Cargo.toml toml 1kb] [Cargo.lock toml 2kb]] | reject ["size", "type"]"#,
|
||||
result: Some(Value::test_list(
|
||||
vec![
|
||||
Value::test_record(record! {"name" => Value::test_string("Cargo.toml")}),
|
||||
Value::test_record(record! {"name" => Value::test_string("Cargo.lock")})],
|
||||
)),
|
||||
},
|
||||
Example {
|
||||
description: "Reject rows by a provided list of rows",
|
||||
example: "let rows = [0 2];[[name type size]; [Cargo.toml toml 1kb] [Cargo.lock toml 2kb] [file.json json 3kb]] | reject $rows",
|
||||
|
|
|
@ -93,6 +93,9 @@ produce a table, a list will produce a list, and a record will produce a record.
|
|||
};
|
||||
new_columns.push(cv.clone());
|
||||
}
|
||||
Value::CellPath { val, .. } => {
|
||||
new_columns.push(val);
|
||||
}
|
||||
y => {
|
||||
return Err(ShellError::CantConvert {
|
||||
to_type: "cell path".into(),
|
||||
|
@ -179,6 +182,15 @@ produce a table, a list will produce a list, and a record will produce a record.
|
|||
example: "let cols = [name type];[[name type size]; [Cargo.toml toml 1kb] [Cargo.lock toml 2kb]] | select $cols",
|
||||
result: None
|
||||
},
|
||||
Example {
|
||||
description: "Select columns by a provided list of columns",
|
||||
example: r#"[[name type size]; [Cargo.toml toml 1kb] [Cargo.lock toml 2kb]] | select ["name", "type"]"#,
|
||||
result: Some(Value::test_list(
|
||||
vec![
|
||||
Value::test_record(record! {"name" => Value::test_string("Cargo.toml"), "type" => Value::test_string("toml")}),
|
||||
Value::test_record(record! {"name" => Value::test_string("Cargo.lock"), "type" => Value::test_string("toml")})],
|
||||
))
|
||||
},
|
||||
Example {
|
||||
description: "Select rows by a provided list of rows",
|
||||
example: "let rows = [0 2];[[name type size]; [Cargo.toml toml 1kb] [Cargo.lock toml 2kb] [file.json json 3kb]] | select $rows",
|
||||
|
|
Loading…
Reference in a new issue