mirror of
https://github.com/nushell/nushell
synced 2025-01-15 14:44:14 +00:00
Updated to new PipeLineData and made the tests run
This commit is contained in:
parent
3a5b943d11
commit
017b1d8996
3 changed files with 45 additions and 27 deletions
|
@ -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));
|
||||
|
|
|
@ -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<Value, ShellError> {
|
||||
input: PipelineData,
|
||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||
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<Example> {
|
||||
|
|
|
@ -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<Value, ShellError> {
|
||||
_input: PipelineData,
|
||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue