use crate::{support::STYLES, traits::CommandTrait};
use ayun_core::{traits::ApplicationTrait, Callback, Result};
use clap::ArgMatches;
use std::sync::Arc;
pub struct Command {
inner: clap::Command,
handler: Callback<ArgMatches, Result<()>>,
}
impl Command {
pub fn new<A, T>() -> Self
where
A: ApplicationTrait,
T: CommandTrait,
{
Self {
inner: T::command().styles(STYLES),
handler: Arc::new(|arg_matches: ArgMatches| T::handle::<A>(arg_matches)),
}
}
pub fn name(&self) -> &str {
self.inner.get_name()
}
pub fn command(&self) -> &clap::Command {
&self.inner
}
pub fn handler(&self) -> &Callback<ArgMatches, Result<()>> {
&self.handler
}
}