rustsec_admin/
application.rs1use std::ops::Deref;
6use std::sync::Arc;
7
8use crate::{commands::AdminCmd, config::AppConfig};
9use abscissa_core::{
10 application::{self, AppCell},
11 config::{self, CfgCell},
12 trace, Application, FrameworkError, StandardPaths,
13};
14
15pub static APPLICATION: AppCell<AdminApp> = AppCell::new();
17
18pub fn app_reader() -> &'static AdminApp {
22 APPLICATION.deref()
23}
24
25pub fn app_writer() -> &'static AdminApp {
27 APPLICATION.deref()
28}
29
30pub fn app_config() -> config::Reader<AppConfig> {
34 APPLICATION.config.read()
35}
36
37#[derive(Debug, Default)]
39pub struct AdminApp {
40 config: CfgCell<AppConfig>,
42
43 state: application::State<Self>,
45}
46
47impl Application for AdminApp {
48 type Cmd = AdminCmd;
50
51 type Cfg = AppConfig;
53
54 type Paths = StandardPaths;
56
57 fn config(&self) -> Arc<AppConfig> {
59 self.config.read()
60 }
61
62 fn state(&self) -> &application::State<Self> {
64 &self.state
65 }
66
67 fn register_components(&mut self, command: &Self::Cmd) -> Result<(), FrameworkError> {
69 let components = self.framework_components(command)?;
70 self.state.components_mut().register(components)
71 }
72
73 fn after_config(&mut self, config: Self::Cfg) -> Result<(), FrameworkError> {
75 self.state.components_mut().after_config(&config)?;
77 self.config.set_once(config);
78 Ok(())
79 }
80
81 fn tracing_config(&self, command: &AdminCmd) -> trace::Config {
83 if command.verbose {
84 trace::Config::verbose()
85 } else {
86 trace::Config::default()
87 }
88 }
89}