1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use std::fmt::Debug;
use std::marker::PhantomData;
use super::BaseCommand;
use crate::error::ShiError;
use crate::Result;
#[derive(Debug)]
pub struct EchoCommand<S> {
phantom: PhantomData<S>,
}
impl<S> Default for EchoCommand<S> {
fn default() -> Self {
Self::new()
}
}
impl<S> EchoCommand<S> {
pub fn new() -> EchoCommand<S> {
EchoCommand {
phantom: PhantomData,
}
}
}
impl<S> BaseCommand for EchoCommand<S> {
type State = S;
fn name(&self) -> &str {
"echo"
}
fn validate_args(&self, args: &[String]) -> Result<()> {
if args.is_empty() {
return Err(ShiError::NoArgs);
}
Ok(())
}
fn execute(&self, _: &mut S, args: &[String]) -> Result<String> {
Ok(format!("ECHO: '{:?}'", args))
}
}