remove default.rs

This commit is contained in:
Boog900 2024-12-02 16:27:01 +00:00
parent 8e941f5a2c
commit 509d5cbde2
No known key found for this signature in database
GPG key ID: 42AB1287CB0041C2
4 changed files with 10 additions and 49 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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();
}
}

View file

@ -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();
}
}