ayun_console/support/
command.rs

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