From 509d5cbde2c05d9f54b5abe4a47e0d34150f4ed7 Mon Sep 17 00:00:00 2001 From: Boog900 <54e72d8a-345f-4599-bd90-c6b9bc7d0ec5@aleeas.com> Date: Mon, 2 Dec 2024 16:27:01 +0000 Subject: [PATCH] remove default.rs --- binaries/cuprated/src/config.rs | 1 - binaries/cuprated/src/config/args.rs | 8 ++--- binaries/cuprated/src/config/default.rs | 44 ------------------------- binaries/cuprated/src/constants.rs | 6 ++++ 4 files changed, 10 insertions(+), 49 deletions(-) delete mode 100644 binaries/cuprated/src/config/default.rs diff --git a/binaries/cuprated/src/config.rs b/binaries/cuprated/src/config.rs index 6b1229f8..53a9c6dd 100644 --- a/binaries/cuprated/src/config.rs +++ b/binaries/cuprated/src/config.rs @@ -18,7 +18,6 @@ use cuprate_p2p::block_downloader::BlockDownloaderConfig; use cuprate_p2p_core::{ClearNet, ClearNetServerCfg}; mod args; -mod default; mod fs; mod p2p; mod storage; diff --git a/binaries/cuprated/src/config/args.rs b/binaries/cuprated/src/config/args.rs index c2cd6233..650c8a45 100644 --- a/binaries/cuprated/src/config/args.rs +++ b/binaries/cuprated/src/config/args.rs @@ -1,10 +1,10 @@ -use std::{io::Write, path::PathBuf}; +use std::{io::Write, path::PathBuf, process::exit}; use clap::builder::TypedValueParser; use cuprate_helper::network::Network; -use crate::config::{default::create_default_config_file, Config}; +use crate::{config::Config, constants::EXAMPLE_CONFIG}; /// Cuprate Args. #[derive(clap::Parser, Debug)] @@ -35,8 +35,8 @@ impl Args { /// This may exit the program if a config value was set that requires an early exit. pub fn apply_args(&self, mut config: Config) -> Config { if let Some(config_folder) = self.generate_config.as_ref() { - // This will create the config file and exit. - create_default_config_file(config_folder) + println!("{EXAMPLE_CONFIG}"); + exit(0); }; config.network = self.network; diff --git a/binaries/cuprated/src/config/default.rs b/binaries/cuprated/src/config/default.rs deleted file mode 100644 index 8c9642b8..00000000 --- a/binaries/cuprated/src/config/default.rs +++ /dev/null @@ -1,44 +0,0 @@ -use std::{ - io::Write, - path::{Path, PathBuf}, - str::from_utf8, -}; - -use cuprate_helper::fs::{CUPRATE_CACHE_DIR, DEFAULT_CONFIG_FILE_NAME}; - -use crate::constants::EXAMPLE_CONFIG; - -/// Creates a config file which will be named [`DEFAULT_CONFIG_FILE_NAME`] in the directory given in [`Path`]. -/// -/// This will always terminate the program, on success and failure. -pub fn create_default_config_file(path: &Path) -> ! { - let config_file = path.join(DEFAULT_CONFIG_FILE_NAME); - - tracing::info!("Attempting to create new config file here: {config_file:?}"); - - let mut file = match std::fs::OpenOptions::new() - .write(true) - .create_new(true) - .open(&config_file) - { - Ok(file) => file, - Err(e) => { - tracing::error!("Failed to create config file, got error: {e}"); - std::process::exit(1); - } - }; - - let config = EXAMPLE_CONFIG; - file.write_all(config.as_bytes()).unwrap(); - - std::process::exit(0); -} - -#[cfg(test)] -mod tests { - use crate::{config::Config, constants::EXAMPLE_CONFIG}; - #[test] - fn generate_config_text_is_valid() { - let config: Config = toml::from_str(EXAMPLE_CONFIG).unwrap(); - } -} diff --git a/binaries/cuprated/src/constants.rs b/binaries/cuprated/src/constants.rs index 2f61f252..057e8bd0 100644 --- a/binaries/cuprated/src/constants.rs +++ b/binaries/cuprated/src/constants.rs @@ -23,6 +23,7 @@ pub const EXAMPLE_CONFIG: &str = include_str!("../Cuprated.toml"); #[cfg(test)] mod test { use super::*; + use crate::config::Config; #[test] fn version() { @@ -37,4 +38,9 @@ mod test { assert_eq!(VERSION_BUILD, "0.0.1-release"); } } + + #[test] + fn generate_config_text_is_valid() { + let config: Config = toml::from_str(EXAMPLE_CONFIG).unwrap(); + } }