cli/commands/
abstract_command.rs1use crate::actions::ActionInvocation;
4
5use super::{CommandName, CommandParseError, CommandSpec, command_spec, load_command_invocation};
6
7pub trait AbstractCommand {
13 fn command_name(&self) -> CommandName;
14
15 fn spec(&self) -> &'static CommandSpec {
16 command_spec(self.command_name()).expect("command spec must be registered")
17 }
18
19 fn load<I, S>(&self, args: I) -> Result<ActionInvocation, CommandParseError>
20 where
21 I: IntoIterator<Item = S>,
22 S: Into<String>,
23 {
24 let mut tokens = Vec::new();
25 tokens.push(self.command_name().as_str().to_string());
26 tokens.extend(args.into_iter().map(Into::into));
27 load_command_invocation(tokens)
28 }
29}