mirror of
https://github.com/nushell/nushell
synced 2025-01-04 01:09:05 +00:00
ab915f1c44
This reverts commit bee7c5639c
.
40 lines
920 B
Rust
40 lines
920 B
Rust
use crate::commands::WholeStreamCommand;
|
|
use crate::data::Value;
|
|
use crate::errors::ShellError;
|
|
use crate::prelude::*;
|
|
|
|
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> {
|
|
let input = args.input;
|
|
|
|
Ok(input
|
|
.values
|
|
.map(move |v| {
|
|
let string = String::extract(&v)?;
|
|
ReturnSuccess::value(Value::string(string.trim()).tagged(v.tag()))
|
|
})
|
|
.to_output_stream())
|
|
}
|