tnn/core/api/
core.rs

1use crate::util::parent_command::{CommandHandlerReturnType, ParentCommand};
2use anyhow::Result;
3use clap::{CommandFactory, FromArgMatches};
4
5pub struct Core {
6	command: ParentCommand,
7}
8
9impl<'a> Core {
10	pub fn new(command: ParentCommand) -> Self {
11		Self { command }
12	}
13
14	pub fn add_command<Command: CommandFactory + FromArgMatches + 'static>(
15		mut self,
16		handler: Box<dyn Fn(Command) -> CommandHandlerReturnType>,
17	) -> Result<Self> {
18		self.command = self.command.add_command::<Command>(handler)?;
19		Ok(self)
20	}
21
22	pub fn finish(self) -> ParentCommand {
23		self.command
24	}
25}