nushell/src/commands/trim.rs

42 lines
942 B
Rust
Raw Normal View History

use crate::commands::WholeStreamCommand;
2019-06-01 05:43:59 +02:00
use crate::prelude::*;
use nu_errors::ShellError;
2019-11-30 01:21:05 +01:00
use nu_protocol::{ReturnSuccess, Signature};
2019-06-01 05:43:59 +02:00
pub struct Trim;
impl WholeStreamCommand for Trim {
fn name(&self) -> &str {
"trim"
}
fn signature(&self) -> Signature {
Signature::build("trim")
}
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)
}
}
fn trim(args: CommandArgs, _registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
2019-06-01 05:43:59 +02:00
let input = args.input;
Ok(input
.values
2019-07-09 06:31:26 +02:00
.map(move |v| {
let string = String::extract(&v)?;
ReturnSuccess::value(value::string(string.trim()).into_value(v.tag()))
2019-07-09 06:31:26 +02:00
})
.to_output_stream())
2019-06-01 05:43:59 +02:00
}