diff --git a/crates/nu-command/src/example_test.rs b/crates/nu-command/src/example_test.rs index c7ca4f0011..53e98e4a00 100644 --- a/crates/nu-command/src/example_test.rs +++ b/crates/nu-command/src/example_test.rs @@ -5,7 +5,7 @@ use nu_protocol::{ PipelineData, }; -use super::{From, Into, Split}; +use super::{From, Into, Split, Math}; pub fn test_examples(cmd: impl Command + 'static) { let examples = cmd.examples(); @@ -18,6 +18,7 @@ pub fn test_examples(cmd: impl Command + 'static) { working_set.add_decl(Box::new(From)); working_set.add_decl(Box::new(Into)); working_set.add_decl(Box::new(Split)); + working_set.add_decl(Box::new(Math)); // Adding the command that is being tested to the working set working_set.add_decl(Box::new(cmd)); diff --git a/crates/nu-command/src/math/abs.rs b/crates/nu-command/src/math/abs.rs index e4d201421d..e7f43205d7 100644 --- a/crates/nu-command/src/math/abs.rs +++ b/crates/nu-command/src/math/abs.rs @@ -1,7 +1,8 @@ use nu_protocol::ast::Call; -use nu_protocol::engine::{Command, EvaluationContext}; -use nu_protocol::{Example, ShellError, Signature, Span, Value}; +use nu_protocol::engine::{Command, EngineState, Stack}; +use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, Value}; +#[derive(Clone)] pub struct SubCommand; impl Command for SubCommand { @@ -19,24 +20,31 @@ impl Command for SubCommand { fn run( &self, - _context: &EvaluationContext, + _engine_state: &EngineState, + _stack: &mut Stack, call: &Call, - input: Value, - ) -> Result { + input: PipelineData, + ) -> Result { let head = call.head; - match input { - Value::List { vals, span } => Ok(Value::List { - vals: vals - .into_iter() - .map(move |val| abs_helper(val, head)) - .collect(), - span, - }), - other => match abs_helper(other, head) { - Value::Error { error } => Err(error), - ok => Ok(ok), - }, - } + input.map(move |value| abs_helper(value, head)) + // PipelineData::Value(Value::List { vals, span }) => Ok(Value::List { + // vals: vals + // .into_iter() + // .map(move |val| abs_helper(val, head)) + // .collect(), + // span, + // }), + // PipelineData::Value(other) => match abs_helper(other, head) { + // Value::Error { error } => Err(error), + // ok => Ok(nu_protocolok), + // }, + // _ => Value::Error { + // error: ShellError::UnsupportedInput( + // String::from("Only numerical values are supported"), + // head, + // ), + // }, + // } } fn examples(&self) -> Vec { diff --git a/crates/nu-command/src/math/command.rs b/crates/nu-command/src/math/command.rs index 8eab51b5b5..6efc11f87c 100644 --- a/crates/nu-command/src/math/command.rs +++ b/crates/nu-command/src/math/command.rs @@ -1,8 +1,11 @@ use nu_engine::get_full_help; -use nu_protocol::ast::Call; -use nu_protocol::engine::{Command, EvaluationContext}; -use nu_protocol::{ShellError, Signature, Value}; +use nu_protocol::{ + ast::Call, + engine::{Command, EngineState, Stack}, + IntoPipelineData, PipelineData, Signature, Value, +}; +#[derive(Clone)] pub struct MathCommand; impl Command for MathCommand { @@ -20,13 +23,19 @@ impl Command for MathCommand { fn run( &self, - context: &EvaluationContext, + engine_state: &EngineState, + _stack: &mut Stack, call: &Call, - _input: Value, - ) -> Result { + _input: PipelineData, + ) -> Result { Ok(Value::String { - val: get_full_help(&MathCommand.signature(), &MathCommand.examples(), context), + val: get_full_help( + &MathCommand.signature(), + &MathCommand.examples(), + engine_state, + ), span: call.head, - }) + } + .into_pipeline_data()) } }