use std::sync::Arc;
use crate::{commands::CargoAuditCommand, config::AuditConfig};
use abscissa_core::{
application::{self, AppCell},
config::CfgCell,
terminal::ColorChoice,
trace, Application, FrameworkError, StandardPaths,
};
pub static APP: AppCell<CargoAuditApplication> = AppCell::new();
#[derive(Debug)]
pub struct CargoAuditApplication {
config: CfgCell<AuditConfig>,
state: application::State<Self>,
}
impl Default for CargoAuditApplication {
fn default() -> Self {
Self {
config: CfgCell::default(),
state: application::State::default(),
}
}
}
impl Application for CargoAuditApplication {
type Cmd = CargoAuditCommand;
type Cfg = AuditConfig;
type Paths = StandardPaths;
fn config(&self) -> Arc<AuditConfig> {
self.config.read()
}
fn state(&self) -> &application::State<Self> {
&self.state
}
fn register_components(&mut self, command: &Self::Cmd) -> Result<(), FrameworkError> {
let components = self.framework_components(command)?;
self.state.components_mut().register(components)
}
fn after_config(&mut self, config: Self::Cfg) -> Result<(), FrameworkError> {
self.state.components_mut().after_config(&config)?;
self.config.set_once(config);
Ok(())
}
fn term_colors(&self, entrypoint: &CargoAuditCommand) -> ColorChoice {
entrypoint.color_config().unwrap_or(ColorChoice::Auto)
}
fn tracing_config(&self, command: &CargoAuditCommand) -> trace::Config {
if command.verbose {
trace::Config::verbose()
} else {
trace::Config::default()
}
}
}