2019-06-01 05:43:59 +02: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-16 01:03:49 +02:00
|
|
|
let span = args.name_span;
|
2019-06-01 05:43:59 +02:00
|
|
|
|
|
|
|
Ok(input
|
2019-07-03 22:31:15 +02:00
|
|
|
.values
|
2019-06-01 05:43:59 +02:00
|
|
|
.map(move |v| match v {
|
|
|
|
Value::Primitive(Primitive::String(s)) => {
|
2019-07-03 22:31:15 +02:00
|
|
|
ReturnSuccess::value(Value::Primitive(Primitive::String(s.trim().into())))
|
2019-06-01 05:43:59 +02:00
|
|
|
}
|
2019-07-03 22:31:15 +02:00
|
|
|
_ => Err(ShellError::maybe_labeled_error(
|
2019-06-16 01:03:49 +02:00
|
|
|
"Expected string values from pipeline",
|
|
|
|
"expects strings from pipeline",
|
|
|
|
span,
|
2019-07-03 22:31:15 +02:00
|
|
|
)),
|
2019-06-01 05:43:59 +02:00
|
|
|
})
|
2019-07-03 22:31:15 +02:00
|
|
|
.to_output_stream())
|
2019-06-01 05:43:59 +02:00
|
|
|
}
|