diff --git a/crates/nu-command/src/default_context.rs b/crates/nu-command/src/default_context.rs index 9eb6c1c0bc..8b28172a0a 100644 --- a/crates/nu-command/src/default_context.rs +++ b/crates/nu-command/src/default_context.rs @@ -43,6 +43,8 @@ pub fn create_default_context() -> Rc> { working_set.add_decl(Box::new(Select)); working_set.add_decl(Box::new(Split)); working_set.add_decl(Box::new(SplitChars)); + working_set.add_decl(Box::new(SplitColumn)); + working_set.add_decl(Box::new(SplitRow)); working_set.add_decl(Box::new(Sys)); working_set.add_decl(Box::new(Table)); working_set.add_decl(Box::new(Touch)); diff --git a/crates/nu-command/src/strings/split/chars.rs b/crates/nu-command/src/strings/split/chars.rs index f77f873692..108190c6aa 100644 --- a/crates/nu-command/src/strings/split/chars.rs +++ b/crates/nu-command/src/strings/split/chars.rs @@ -65,69 +65,21 @@ fn split_chars(call: &Call, input: Value) -> Result Value::List { vals: vals .iter() - .flat_map(move |v| { - if let Ok(s) = v.as_string() { - let v_span = v.span(); - s.chars() - .collect::>() - .into_iter() - .map(move |x| Value::String { - val: x.to_string(), - span: v_span, - }) - .collect() - } else { - vec![Value::Error { - error: ShellError::PipelineMismatch { - expected: Type::String, - expected_span: name, - origin: v.span(), - }, - }] - } - }) + .flat_map(|x| split_chars_helper(x, name)) .collect(), span, }, Value::Stream { stream, span } => Value::Stream { stream: stream - .flat_map(move |v| { - if let Ok(s) = v.as_string() { - let v_span = v.span(); - s.chars() - .collect::>() - .into_iter() - .map(move |x| Value::String { - val: x.to_string(), - span: v_span, - }) - .collect() - } else { - vec![Value::Error { - error: ShellError::PipelineMismatch { - expected: Type::String, - expected_span: name, - origin: v.span(), - }, - }] - } - }) + .flat_map(move |x| split_chars_helper(&x, name)) .into_value_stream(), span, }, v => { let v_span = v.span(); - if let Ok(s) = v.as_string() { + if v.as_string().is_ok() { Value::List { - vals: s - .chars() - .collect::>() - .into_iter() - .map(move |x| Value::String { - val: x.to_string(), - span: v_span, - }) - .collect(), + vals: split_chars_helper(&v, name), span: v_span, } } else { @@ -143,6 +95,28 @@ fn split_chars(call: &Call, input: Value) -> Result Vec { + if let Ok(s) = v.as_string() { + let v_span = v.span(); + s.chars() + .collect::>() + .into_iter() + .map(move |x| Value::String { + val: x.to_string(), + span: v_span, + }) + .collect() + } else { + vec![Value::Error { + error: ShellError::PipelineMismatch { + expected: Type::String, + expected_span: name, + origin: v.span(), + }, + }] + } +} + // #[cfg(test)] // mod tests { // use super::ShellError; diff --git a/crates/nu-command/src/strings/split/mod.rs b/crates/nu-command/src/strings/split/mod.rs index 3a65f0e124..c6e6da0171 100644 --- a/crates/nu-command/src/strings/split/mod.rs +++ b/crates/nu-command/src/strings/split/mod.rs @@ -1,9 +1,9 @@ pub mod chars; -// pub mod column; +pub mod column; pub mod command; -// pub mod row; +pub mod row; pub use chars::SubCommand as SplitChars; -// pub use column::SubCommand as SplitColumn; +pub use column::SubCommand as SplitColumn; pub use command::SplitCommand as Split; -// pub use row::SubCommand as SplitRow; +pub use row::SubCommand as SplitRow;