soph_console/support/
command.rs1use crate::{
2 support::STYLES,
3 traits::{ApplicationTrait, CommandTrait},
4 Handler,
5};
6use clap::ArgMatches;
7use std::sync::Arc;
8
9pub struct Command {
10 inner: clap::Command,
11 handler: Handler,
12}
13
14impl Command {
15 pub fn new<A, T>() -> Self
16 where
17 A: ApplicationTrait,
18 T: CommandTrait,
19 {
20 Self {
21 inner: T::command().styles(STYLES),
22 handler: Arc::new(|arg_matches: ArgMatches| T::handle::<A>(arg_matches)),
23 }
24 }
25
26 pub fn name(&self) -> &str {
27 self.inner.get_name()
28 }
29
30 pub fn command(&self) -> &clap::Command {
31 &self.inner
32 }
33
34 pub fn handler(&self) -> &Handler {
35 &self.handler
36 }
37}