2019-06-01 03:43:59 +00:00
|
|
|
use crate::errors::ShellError;
|
|
|
|
use crate::object::{Primitive, Value};
|
|
|
|
use crate::prelude::*;
|
|
|
|
|
|
|
|
// TODO: "Amount remaining" wrapper
|
|
|
|
|
|
|
|
pub fn trim(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|
|
|
let input = args.input;
|
2019-06-15 23:03:49 +00:00
|
|
|
let span = args.name_span;
|
2019-06-01 03:43:59 +00:00
|
|
|
|
|
|
|
Ok(input
|
|
|
|
.map(move |v| match v {
|
|
|
|
Value::Primitive(Primitive::String(s)) => {
|
2019-06-22 20:46:16 +00:00
|
|
|
ReturnValue::Value(Value::Primitive(Primitive::String(s.trim().into())))
|
2019-06-01 03:43:59 +00:00
|
|
|
}
|
2019-06-15 23:03:49 +00:00
|
|
|
_ => ReturnValue::Value(Value::Error(Box::new(ShellError::maybe_labeled_error(
|
|
|
|
"Expected string values from pipeline",
|
|
|
|
"expects strings from pipeline",
|
|
|
|
span,
|
|
|
|
)))),
|
2019-06-01 03:43:59 +00:00
|
|
|
})
|
|
|
|
.boxed())
|
|
|
|
}
|