From d7ff9fb7b72ae5ee0615f182cb36727a8e38a1f9 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Sat, 1 Jun 2019 15:43:59 +1200 Subject: [PATCH] Trim (#52) Add a simple trim command --- src/cli.rs | 1 + src/commands.rs | 1 + src/commands/trim.rs | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 src/commands/trim.rs diff --git a/src/cli.rs b/src/cli.rs index 98e46535e7..a3785e8cbe 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -56,6 +56,7 @@ pub async fn cli() -> Result<(), Box> { 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), diff --git a/src/commands.rs b/src/commands.rs index 7978249bdf..23b79fad09 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -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_; diff --git a/src/commands/trim.rs b/src/commands/trim.rs new file mode 100644 index 0000000000..2974b4e65b --- /dev/null +++ b/src/commands/trim.rs @@ -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 { + 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()) +}