diff --git a/src/cli.rs b/src/cli.rs index 98e46535e..a3785e8cb 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 7978249bd..23b79fad0 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 000000000..2974b4e65 --- /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()) +}