mirror of
https://github.com/nushell/nushell.git
synced 2024-12-13 10:41:52 +01:00
b2c5af457e
This improves incremental build time when working on what was previously the root package. For example, previously all plugins would be rebuilt with a change to `src/commands/classified/external.rs`, but now only `nu-cli` will have to be rebuilt (and anything that depends on it).
42 lines
965 B
Rust
42 lines
965 B
Rust
use crate::commands::WholeStreamCommand;
|
|
|
|
use crate::prelude::*;
|
|
use nu_errors::ShellError;
|
|
use nu_protocol::{ReturnSuccess, Signature, UntaggedValue};
|
|
|
|
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(UntaggedValue::string(string.trim()).into_value(v.tag()))
|
|
})
|
|
.to_output_stream())
|
|
}
|