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;
13pub mod weidu_log_options;
14
15pub struct Config {
16 pub args: Args,
17 pub parser: Arc<ParserConfig>,
18}
19
20impl Config {
21 pub fn new(parser_config_location: &str) -> Self {
22 let parser_config: Arc<ParserConfig> = if let Ok(config) =
23 confy::load::<ParserConfig>(CARGO_PKG_NAME, parser_config_location)
24 && config.metadata.mod_installer_version == env!("CARGO_PKG_VERSION")
25 {
26 log::debug!("Using existing config: {:?}", config);
27 Arc::new(config)
28 } else {
29 log::debug!("Creating new config");
30 let config = Arc::new(ParserConfig::default());
31 let _ = confy::store(
32 CARGO_PKG_NAME,
33 parser_config_location,
34 config.clone().as_ref(),
35 );
36 config
37 };
38 Self {
39 args: Args::parse(),
40 parser: parser_config,
41 }
42 }
43}