1use std::sync::Arc;
2
3use args::{Args, CARGO_PKG_NAME};
4use clap::Parser;
5use parser_config::ParserConfig;
6
7pub mod args;
8mod colors;
9pub mod log_options;
10mod meta;
11pub mod parser_config;
12pub mod state;
13
14pub struct Config {
15 pub args: Args,
16 pub parser: Arc<ParserConfig>,
17}
18
19impl Config {
20 pub fn new(parser_config_location: &str) -> Self {
21 let parser_config: Arc<ParserConfig> = if let Ok(config) =
22 confy::load::<ParserConfig>(CARGO_PKG_NAME, parser_config_location)
23 && config.metadata.mod_installer_version == env!("CARGO_PKG_VERSION")
24 {
25 log::debug!("Using existing config: {:?}", config);
26 Arc::new(config)
27 } else {
28 log::debug!("Creating new config");
29 let config = Arc::new(ParserConfig::default());
30 let _ = confy::store(
31 CARGO_PKG_NAME,
32 parser_config_location,
33 config.clone().as_ref(),
34 );
35 config
36 };
37 Self {
38 args: Args::parse(),
39 parser: parser_config,
40 }
41 }
42}