diff --git a/.gitignore b/.gitignore index f565b0f..449998f 100644 --- a/.gitignore +++ b/.gitignore @@ -27,4 +27,4 @@ target *.txt *.bak -config.toml \ No newline at end of file +Config.toml \ No newline at end of file diff --git a/Config.toml.example b/Config.toml.example new file mode 100644 index 0000000..f792c6c --- /dev/null +++ b/Config.toml.example @@ -0,0 +1,7 @@ +input_path = "keys.txt" +output_path = "output_keys.txt" +backup_path = "backup_keys.txt" +api_host = "https://generativelanguage.googleapis.com/" +timeout_sec = 20 +concurrency = 30 +proxy = "http://username:password@host:port" diff --git a/src/config/basic_config.rs b/src/config/basic_config.rs index c4a1b54..50efcbc 100644 --- a/src/config/basic_config.rs +++ b/src/config/basic_config.rs @@ -64,7 +64,7 @@ impl Default for KeyCheckerConfig { impl KeyCheckerConfig { pub fn load_config() -> Result { // Define the path to the configuration file - static CONFIG_PATH: LazyLock = LazyLock::new(|| "config.toml".into()); + static CONFIG_PATH: LazyLock = LazyLock::new(|| "Config.toml".into()); // Check if config.toml exists, if not create it with default values if !CONFIG_PATH.exists() { @@ -74,12 +74,39 @@ impl KeyCheckerConfig { } // Load configuration from config.toml, environment variables, and defaults - let config = Figment::new() + let mut figment = Figment::new() .merge(Serialized::defaults(Self::default())) .merge(Toml::file(CONFIG_PATH.as_path())) - .merge(Env::prefixed("KEYCHECKER_")) - .merge(Serialized::defaults(Self::parse())) - .extract()?; + .merge(Env::prefixed("KEYCHECKER_")); + + // Only merge non-None command line arguments + let cli_args = Self::parse(); + if let Some(input_path) = cli_args.input_path { + figment = figment.merge(("input_path", input_path)); + } + if let Some(output_path) = cli_args.output_path { + figment = figment.merge(("output_path", output_path)); + } + if let Some(backup_path) = cli_args.backup_path { + figment = figment.merge(("backup_path", backup_path)); + } + if let Some(api_host) = cli_args.api_host { + figment = figment.merge(("api_host", api_host)); + } + if let Some(timeout_sec) = cli_args.timeout_sec { + figment = figment.merge(("timeout_sec", timeout_sec)); + } + if let Some(concurrency) = cli_args.concurrency { + figment = figment.merge(("concurrency", concurrency)); + } + if let Some(proxy) = cli_args.proxy { + figment = figment.merge(("proxy", proxy)); + } + + let config = figment.extract()?; + + println!("Final loaded config: {:?}", config); + Ok(config) } pub fn input_path(&self) -> PathBuf {