mirror of
https://github.com/nushell/nushell.git
synced 2025-02-19 12:01:42 +01:00
Updated to new PipeLineData and made the tests run
This commit is contained in:
parent
3a5b943d11
commit
017b1d8996
@ -5,7 +5,7 @@ use nu_protocol::{
|
|||||||
PipelineData,
|
PipelineData,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{From, Into, Split};
|
use super::{From, Into, Split, Math};
|
||||||
|
|
||||||
pub fn test_examples(cmd: impl Command + 'static) {
|
pub fn test_examples(cmd: impl Command + 'static) {
|
||||||
let examples = cmd.examples();
|
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(From));
|
||||||
working_set.add_decl(Box::new(Into));
|
working_set.add_decl(Box::new(Into));
|
||||||
working_set.add_decl(Box::new(Split));
|
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
|
// Adding the command that is being tested to the working set
|
||||||
working_set.add_decl(Box::new(cmd));
|
working_set.add_decl(Box::new(cmd));
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
use nu_protocol::ast::Call;
|
use nu_protocol::ast::Call;
|
||||||
use nu_protocol::engine::{Command, EvaluationContext};
|
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||||
use nu_protocol::{Example, ShellError, Signature, Span, Value};
|
use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, Value};
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct SubCommand;
|
pub struct SubCommand;
|
||||||
|
|
||||||
impl Command for SubCommand {
|
impl Command for SubCommand {
|
||||||
@ -19,24 +20,31 @@ impl Command for SubCommand {
|
|||||||
|
|
||||||
fn run(
|
fn run(
|
||||||
&self,
|
&self,
|
||||||
_context: &EvaluationContext,
|
_engine_state: &EngineState,
|
||||||
|
_stack: &mut Stack,
|
||||||
call: &Call,
|
call: &Call,
|
||||||
input: Value,
|
input: PipelineData,
|
||||||
) -> Result<Value, ShellError> {
|
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||||
let head = call.head;
|
let head = call.head;
|
||||||
match input {
|
input.map(move |value| abs_helper(value, head))
|
||||||
Value::List { vals, span } => Ok(Value::List {
|
// PipelineData::Value(Value::List { vals, span }) => Ok(Value::List {
|
||||||
vals: vals
|
// vals: vals
|
||||||
.into_iter()
|
// .into_iter()
|
||||||
.map(move |val| abs_helper(val, head))
|
// .map(move |val| abs_helper(val, head))
|
||||||
.collect(),
|
// .collect(),
|
||||||
span,
|
// span,
|
||||||
}),
|
// }),
|
||||||
other => match abs_helper(other, head) {
|
// PipelineData::Value(other) => match abs_helper(other, head) {
|
||||||
Value::Error { error } => Err(error),
|
// Value::Error { error } => Err(error),
|
||||||
ok => Ok(ok),
|
// ok => Ok(nu_protocolok),
|
||||||
},
|
// },
|
||||||
}
|
// _ => Value::Error {
|
||||||
|
// error: ShellError::UnsupportedInput(
|
||||||
|
// String::from("Only numerical values are supported"),
|
||||||
|
// head,
|
||||||
|
// ),
|
||||||
|
// },
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
use nu_engine::get_full_help;
|
use nu_engine::get_full_help;
|
||||||
use nu_protocol::ast::Call;
|
use nu_protocol::{
|
||||||
use nu_protocol::engine::{Command, EvaluationContext};
|
ast::Call,
|
||||||
use nu_protocol::{ShellError, Signature, Value};
|
engine::{Command, EngineState, Stack},
|
||||||
|
IntoPipelineData, PipelineData, Signature, Value,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct MathCommand;
|
pub struct MathCommand;
|
||||||
|
|
||||||
impl Command for MathCommand {
|
impl Command for MathCommand {
|
||||||
@ -20,13 +23,19 @@ impl Command for MathCommand {
|
|||||||
|
|
||||||
fn run(
|
fn run(
|
||||||
&self,
|
&self,
|
||||||
context: &EvaluationContext,
|
engine_state: &EngineState,
|
||||||
|
_stack: &mut Stack,
|
||||||
call: &Call,
|
call: &Call,
|
||||||
_input: Value,
|
_input: PipelineData,
|
||||||
) -> Result<Value, ShellError> {
|
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||||
Ok(Value::String {
|
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,
|
span: call.head,
|
||||||
})
|
}
|
||||||
|
.into_pipeline_data())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user