nushell/crates/nu-command/src/core_commands/echo.rs

56 lines
1.3 KiB
Rust
Raw Normal View History

use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
2021-11-01 09:37:07 +01:00
use nu_protocol::{Example, PipelineData, ShellError, Signature, SyntaxShape, Value};
#[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> {
Ok(input)
}
2021-11-01 09:37:07 +01:00
fn examples(&self) -> Vec<Example> {
vec![
Example {
description: "Put a hello message in the pipeline",
example: "echo 'hello'",
result: Some(Value::test_string("hello")),
},
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 {})
}
}