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))
}
}