cargo_audit/
application.rs1use std::sync::Arc;
6
7use crate::{commands::CargoAuditCommand, config::AuditConfig};
8use abscissa_core::{
9 application::{self, AppCell},
10 config::CfgCell,
11 terminal::ColorChoice,
12 trace, Application, FrameworkError, StandardPaths,
13};
14
15pub static APP: AppCell<CargoAuditApplication> = AppCell::new();
17
18#[derive(Debug)]
20pub struct CargoAuditApplication {
21 config: CfgCell<AuditConfig>,
23
24 state: application::State<Self>,
26}
27
28impl Default for CargoAuditApplication {
33 fn default() -> Self {
34 Self {
35 config: CfgCell::default(),
36 state: application::State::default(),
37 }
38 }
39}
40
41impl Application for CargoAuditApplication {
42 type Cmd = CargoAuditCommand;
44
45 type Cfg = AuditConfig;
47
48 type Paths = StandardPaths;
50
51 fn config(&self) -> Arc<AuditConfig> {
53 self.config.read()
54 }
55
56 fn state(&self) -> &application::State<Self> {
58 &self.state
59 }
60
61 fn register_components(&mut self, command: &Self::Cmd) -> Result<(), FrameworkError> {
63 let components = self.framework_components(command)?;
64 self.state.components_mut().register(components)
65 }
66
67 fn after_config(&mut self, config: Self::Cfg) -> Result<(), FrameworkError> {
69 self.state.components_mut().after_config(&config)?;
71 self.config.set_once(config);
72 Ok(())
73 }
74
75 fn term_colors(&self, entrypoint: &CargoAuditCommand) -> ColorChoice {
77 entrypoint.term_colors()
78 }
79
80 fn tracing_config(&self, command: &CargoAuditCommand) -> trace::Config {
82 if command.verbose {
83 trace::Config::verbose()
84 } else {
85 trace::Config::default()
86 }
87 }
88}