use crate::actions::ActionInvocation;
use super::{CommandName, CommandParseError, CommandSpec, command_spec, load_command_invocation};
pub trait AbstractCommand {
fn command_name(&self) -> CommandName;
fn spec(&self) -> &'static CommandSpec {
command_spec(self.command_name()).expect("command spec must be registered")
}
fn load<I, S>(&self, args: I) -> Result<ActionInvocation, CommandParseError>
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
let mut tokens = Vec::new();
tokens.push(self.command_name().as_str().to_string());
tokens.extend(args.into_iter().map(Into::into));
load_command_invocation(tokens)
}
}