mirror of
https://github.com/nushell/nushell.git
synced 2024-12-04 06:15:27 +01:00
5d4097073b
--loglevel sets the log level for all of nu --develop takes a list of modules and turns on trace mode for them
38 lines
1.1 KiB
Rust
38 lines
1.1 KiB
Rust
use crate::errors::ShellError;
|
|
use crate::object::{Primitive, Value};
|
|
use crate::prelude::*;
|
|
use log::trace;
|
|
|
|
// TODO: "Amount remaining" wrapper
|
|
|
|
pub fn split_row(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|
let input = args.input;
|
|
let args = args.positional;
|
|
|
|
let stream = input
|
|
.map(move |v| match v {
|
|
Value::Primitive(Primitive::String(s)) => {
|
|
let splitter = args[0].as_string().unwrap().replace("\\n", "\n");
|
|
trace!("splitting with {:?}", splitter);
|
|
let split_result: Vec<_> = s.split(&splitter).filter(|s| s.trim() != "").collect();
|
|
|
|
trace!("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 result = VecDeque::new();
|
|
result
|
|
}
|
|
})
|
|
.flatten();
|
|
|
|
Ok(stream.boxed())
|
|
}
|