nushell/src/commands/trim.rs

27 lines
831 B
Rust
Raw Normal View History

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
.values
2019-07-09 04:31:26 +00:00
.map(move |v| {
let string = String::extract(&v)?;
ReturnSuccess::value(Value::string(string.trim()).spanned(v.span))
})
2019-07-08 16:44:53 +00:00
// Value::Primitive(Primitive::String(s)) => {
// ReturnSuccess::value(Value::Primitive(Primitive::String(s.trim().into())))
// }
// _ => Err(ShellError::maybe_labeled_error(
// "Expected string values from pipeline",
// "expects strings from pipeline",
// span,
// )),
.to_output_stream())
2019-06-01 03:43:59 +00:00
}