use crate::{commands::KmsCommand, config::KmsConfig};
use abscissa_core::{
application::{self, AppCell},
config::{self, CfgCell},
trace, Application, FrameworkError, StandardPaths,
};
pub static APP: AppCell<KmsApplication> = AppCell::new();
#[derive(Debug, Default)]
pub struct KmsApplication {
config: CfgCell<KmsConfig>,
state: application::State<Self>,
}
impl Application for KmsApplication {
type Cmd = KmsCommand;
type Cfg = KmsConfig;
type Paths = StandardPaths;
fn config(&self) -> config::Reader<KmsConfig> {
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)?;
let mut component_registry = self.state.components_mut();
component_registry.register(components)
}
fn after_config(&mut self, config: Self::Cfg) -> Result<(), FrameworkError> {
let mut component_registry = self.state.components_mut();
component_registry.after_config(&config)?;
self.config.set_once(config);
Ok(())
}
fn tracing_config(&self, command: &KmsCommand) -> trace::Config {
if command.verbose() {
trace::Config::verbose()
} else {
trace::Config::default()
}
}
}