Fixing run implementation for Echo

Values to echo need to be extracted from the call, and then converted
into PipelineData.

I also updated the first example so that its result is a List,
as in the reference implementation.
This commit is contained in:
Antonio Natilla 2021-11-01 12:51:46 +01:00
parent 89225cf55c
commit 1c2741c598

View file

@ -1,6 +1,9 @@
use nu_engine::CallExt;
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Example, PipelineData, ShellError, Signature, SyntaxShape, Value}; use nu_protocol::{
Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value, ValueStream,
};
#[derive(Clone)] #[derive(Clone)]
pub struct Echo; pub struct Echo;
@ -20,12 +23,17 @@ impl Command for Echo {
fn run( fn run(
&self, &self,
_engine_state: &EngineState, engine_state: &EngineState,
_stack: &mut Stack, stack: &mut Stack,
_call: &Call, call: &Call,
input: PipelineData, _input: PipelineData,
) -> Result<PipelineData, ShellError> { ) -> Result<PipelineData, ShellError> {
Ok(input) call.rest(engine_state, stack, 0).map(|to_be_echoed| {
PipelineData::Stream(ValueStream::from_stream(
to_be_echoed.into_iter(),
engine_state.ctrlc.clone(),
))
})
} }
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
@ -33,7 +41,10 @@ impl Command for Echo {
Example { Example {
description: "Put a hello message in the pipeline", description: "Put a hello message in the pipeline",
example: "echo 'hello'", example: "echo 'hello'",
result: Some(Value::test_string("hello")), result: Some(Value::List {
vals: vec![Value::test_string("hello")],
span: Span::new(0, 0),
}),
}, },
Example { Example {
description: "Print the value of the special '$nu' variable", description: "Print the value of the special '$nu' variable",