Add a simple trim command
This commit is contained in:
Jonathan Turner 2019-06-01 15:43:59 +12:00 committed by GitHub
parent 5043367d11
commit d7ff9fb7b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 0 deletions

View file

@ -56,6 +56,7 @@ pub async fn cli() -> Result<(), Box<Error>> {
command("split-row", split_row::split_row),
command("reject", reject::reject),
command("select", select::select),
command("trim", trim::trim),
command("to-array", to_array::to_array),
command("to-json", to_json::to_json),
Arc::new(Where),

View file

@ -17,6 +17,7 @@ crate mod split_row;
crate mod take;
crate mod to_array;
crate mod to_json;
crate mod trim;
crate mod view;
crate mod where_;

18
src/commands/trim.rs Normal file
View file

@ -0,0 +1,18 @@
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;
Ok(input
.map(move |v| match v {
Value::Primitive(Primitive::String(s)) => {
ReturnValue::Value(Value::Primitive(Primitive::String(s.trim().to_string())))
}
x => ReturnValue::Value(x),
})
.boxed())
}