mirror of
https://github.com/nushell/nushell.git
synced 2024-12-22 15:13:01 +01:00
Add row-split
This commit is contained in:
parent
8f5d959692
commit
dd35b2460c
@ -52,7 +52,8 @@ pub async fn cli() -> Result<(), Box<Error>> {
|
|||||||
command("from-json", from_json::from_json),
|
command("from-json", from_json::from_json),
|
||||||
command("open", open::open),
|
command("open", open::open),
|
||||||
command("column", column::column),
|
command("column", column::column),
|
||||||
command("split", split::split),
|
command("column-split", col_split::col_split),
|
||||||
|
command("row-split", row_split::row_split),
|
||||||
command("reject", reject::reject),
|
command("reject", reject::reject),
|
||||||
command("select", select::select),
|
command("select", select::select),
|
||||||
command("to-array", to_array::to_array),
|
command("to-array", to_array::to_array),
|
||||||
|
@ -12,7 +12,8 @@ crate mod select;
|
|||||||
crate mod size;
|
crate mod size;
|
||||||
crate mod skip;
|
crate mod skip;
|
||||||
crate mod sort_by;
|
crate mod sort_by;
|
||||||
crate mod split;
|
crate mod col_split;
|
||||||
|
crate mod row_split;
|
||||||
crate mod take;
|
crate mod take;
|
||||||
crate mod to_array;
|
crate mod to_array;
|
||||||
crate mod to_json;
|
crate mod to_json;
|
||||||
|
@ -5,7 +5,7 @@ use log::debug;
|
|||||||
|
|
||||||
// TODO: "Amount remaining" wrapper
|
// TODO: "Amount remaining" wrapper
|
||||||
|
|
||||||
pub fn split(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
pub fn col_split(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
//let splitter = args.args[0].as_string()?;
|
//let splitter = args.args[0].as_string()?;
|
||||||
let input = args.input;
|
let input = args.input;
|
||||||
let args = args.args;
|
let args = args.args;
|
||||||
@ -13,7 +13,7 @@ pub fn split(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
Ok(input
|
Ok(input
|
||||||
.map(move |v| match v {
|
.map(move |v| match v {
|
||||||
Value::Primitive(Primitive::String(s)) => {
|
Value::Primitive(Primitive::String(s)) => {
|
||||||
let splitter = args[0].as_string().unwrap();
|
let splitter = args[0].as_string().unwrap().replace("\\n", "\n");
|
||||||
debug!("splitting with {:?}", splitter);
|
debug!("splitting with {:?}", splitter);
|
||||||
let split_result: Vec<_> = s.split(&splitter).filter(|s| s.trim() != "").collect();
|
let split_result: Vec<_> = s.split(&splitter).filter(|s| s.trim() != "").collect();
|
||||||
|
|
37
src/commands/row_split.rs
Normal file
37
src/commands/row_split.rs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
use crate::errors::ShellError;
|
||||||
|
use crate::object::{Primitive, Value};
|
||||||
|
use crate::prelude::*;
|
||||||
|
use log::debug;
|
||||||
|
|
||||||
|
// TODO: "Amount remaining" wrapper
|
||||||
|
|
||||||
|
pub fn row_split(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
|
//let splitter = args.args[0].as_string()?;
|
||||||
|
let input = args.input;
|
||||||
|
let args = args.args;
|
||||||
|
|
||||||
|
let stream = input
|
||||||
|
.map(move |v| match v {
|
||||||
|
Value::Primitive(Primitive::String(s)) => {
|
||||||
|
let splitter = args[0].as_string().unwrap().replace("\\n", "\n");
|
||||||
|
debug!("splitting with {:?}", splitter);
|
||||||
|
let split_result: Vec<_> = s.split(&splitter).filter(|s| s.trim() != "").collect();
|
||||||
|
|
||||||
|
debug!("split result = {:?}", split_result);
|
||||||
|
|
||||||
|
let mut result = VecDeque::new();
|
||||||
|
for s in split_result {
|
||||||
|
result.push_back(ReturnValue::Value(Value::Primitive(Primitive::String(s.to_string()))));
|
||||||
|
}
|
||||||
|
result
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
let mut result = VecDeque::new();
|
||||||
|
result.push_back(ReturnValue::Value(Value::Object(crate::object::Dictionary::default())));
|
||||||
|
result
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.flatten();
|
||||||
|
|
||||||
|
Ok(stream.boxed())
|
||||||
|
}
|
@ -183,7 +183,7 @@ impl Value {
|
|||||||
|
|
||||||
crate fn compare(&self, operator: ast::Operator, other: &Value) -> Option<bool> {
|
crate fn compare(&self, operator: ast::Operator, other: &Value) -> Option<bool> {
|
||||||
match operator {
|
match operator {
|
||||||
ast::Operator::Equal | ast::Operator::NotEqual => unimplemented!(),
|
//ast::Operator::Equal | ast::Operator::NotEqual => unimplemented!(),
|
||||||
_ => {
|
_ => {
|
||||||
let coerced = coerce_compare(self, other)?;
|
let coerced = coerce_compare(self, other)?;
|
||||||
let ordering = coerced.compare();
|
let ordering = coerced.compare();
|
||||||
|
Loading…
Reference in New Issue
Block a user