mirror of
https://github.com/nushell/nushell
synced 2024-12-30 15:03:25 +00:00
Merge pull request #271 from aslynatilla/porting-echo
Porting echo command
This commit is contained in:
commit
e14945fdf5
3 changed files with 69 additions and 0 deletions
66
crates/nu-command/src/core_commands/echo.rs
Normal file
66
crates/nu-command/src/core_commands/echo.rs
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
use nu_engine::CallExt;
|
||||||
|
use nu_protocol::ast::Call;
|
||||||
|
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||||
|
use nu_protocol::{
|
||||||
|
Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value, ValueStream,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct Echo;
|
||||||
|
|
||||||
|
impl Command for Echo {
|
||||||
|
fn name(&self) -> &str {
|
||||||
|
"echo"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn usage(&self) -> &str {
|
||||||
|
"Echo the arguments back to the user."
|
||||||
|
}
|
||||||
|
|
||||||
|
fn signature(&self) -> Signature {
|
||||||
|
Signature::build("echo").rest("rest", SyntaxShape::Any, "the values to echo")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run(
|
||||||
|
&self,
|
||||||
|
engine_state: &EngineState,
|
||||||
|
stack: &mut Stack,
|
||||||
|
call: &Call,
|
||||||
|
_input: PipelineData,
|
||||||
|
) -> Result<PipelineData, ShellError> {
|
||||||
|
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> {
|
||||||
|
vec![
|
||||||
|
Example {
|
||||||
|
description: "Put a hello message in the pipeline",
|
||||||
|
example: "echo 'hello'",
|
||||||
|
result: Some(Value::List {
|
||||||
|
vals: vec![Value::test_string("hello")],
|
||||||
|
span: Span::new(0, 0),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
Example {
|
||||||
|
description: "Print the value of the special '$nu' variable",
|
||||||
|
example: "echo $nu",
|
||||||
|
result: None,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
#[test]
|
||||||
|
fn test_examples() {
|
||||||
|
use super::Echo;
|
||||||
|
use crate::test_examples;
|
||||||
|
test_examples(Echo {})
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
mod alias;
|
mod alias;
|
||||||
mod def;
|
mod def;
|
||||||
mod do_;
|
mod do_;
|
||||||
|
mod echo;
|
||||||
mod export_def;
|
mod export_def;
|
||||||
mod for_;
|
mod for_;
|
||||||
mod help;
|
mod help;
|
||||||
|
@ -14,6 +15,7 @@ mod use_;
|
||||||
pub use alias::Alias;
|
pub use alias::Alias;
|
||||||
pub use def::Def;
|
pub use def::Def;
|
||||||
pub use do_::Do;
|
pub use do_::Do;
|
||||||
|
pub use echo::Echo;
|
||||||
pub use export_def::ExportDef;
|
pub use export_def::ExportDef;
|
||||||
pub use for_::For;
|
pub use for_::For;
|
||||||
pub use help::Help;
|
pub use help::Help;
|
||||||
|
|
|
@ -30,6 +30,7 @@ pub fn create_default_context() -> EngineState {
|
||||||
Def,
|
Def,
|
||||||
Do,
|
Do,
|
||||||
Each,
|
Each,
|
||||||
|
Echo,
|
||||||
ExportDef,
|
ExportDef,
|
||||||
External,
|
External,
|
||||||
For,
|
For,
|
||||||
|
|
Loading…
Reference in a new issue