2019-08-19 05:16:39 +00:00
|
|
|
use crate::commands::WholeStreamCommand;
|
2019-09-05 16:23:42 +00:00
|
|
|
use crate::data::Value;
|
2019-09-11 14:36:50 +00:00
|
|
|
use crate::errors::ShellError;
|
2019-06-01 03:43:59 +00:00
|
|
|
use crate::prelude::*;
|
|
|
|
|
2019-08-19 05:16:39 +00:00
|
|
|
pub struct Trim;
|
|
|
|
|
|
|
|
impl WholeStreamCommand for Trim {
|
|
|
|
fn name(&self) -> &str {
|
|
|
|
"trim"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn signature(&self) -> Signature {
|
|
|
|
Signature::build("trim")
|
|
|
|
}
|
2019-08-29 22:52:32 +00:00
|
|
|
|
|
|
|
fn usage(&self) -> &str {
|
|
|
|
"Trim leading and following whitespace from text data."
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run(
|
|
|
|
&self,
|
|
|
|
args: CommandArgs,
|
|
|
|
registry: &CommandRegistry,
|
|
|
|
) -> Result<OutputStream, ShellError> {
|
|
|
|
trim(args, registry)
|
|
|
|
}
|
2019-08-19 05:16:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn trim(args: CommandArgs, _registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
|
2019-06-01 03:43:59 +00:00
|
|
|
let input = args.input;
|
|
|
|
|
|
|
|
Ok(input
|
2019-07-03 20:31:15 +00:00
|
|
|
.values
|
2019-07-09 04:31:26 +00:00
|
|
|
.map(move |v| {
|
|
|
|
let string = String::extract(&v)?;
|
2019-09-14 16:30:24 +00:00
|
|
|
ReturnSuccess::value(Value::string(string.trim()).tagged(v.tag()))
|
2019-07-09 04:31:26 +00:00
|
|
|
})
|
2019-07-03 20:31:15 +00:00
|
|
|
.to_output_stream())
|
2019-06-01 03:43:59 +00:00
|
|
|
}
|