mirror of
https://github.com/Cuprate/cuprate.git
synced 2025-03-23 23:58:54 +00:00
remove default.rs
This commit is contained in:
parent
8e941f5a2c
commit
509d5cbde2
4 changed files with 10 additions and 49 deletions
|
@ -18,7 +18,6 @@ use cuprate_p2p::block_downloader::BlockDownloaderConfig;
|
||||||
use cuprate_p2p_core::{ClearNet, ClearNetServerCfg};
|
use cuprate_p2p_core::{ClearNet, ClearNetServerCfg};
|
||||||
|
|
||||||
mod args;
|
mod args;
|
||||||
mod default;
|
|
||||||
mod fs;
|
mod fs;
|
||||||
mod p2p;
|
mod p2p;
|
||||||
mod storage;
|
mod storage;
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use std::{io::Write, path::PathBuf};
|
use std::{io::Write, path::PathBuf, process::exit};
|
||||||
|
|
||||||
use clap::builder::TypedValueParser;
|
use clap::builder::TypedValueParser;
|
||||||
|
|
||||||
use cuprate_helper::network::Network;
|
use cuprate_helper::network::Network;
|
||||||
|
|
||||||
use crate::config::{default::create_default_config_file, Config};
|
use crate::{config::Config, constants::EXAMPLE_CONFIG};
|
||||||
|
|
||||||
/// Cuprate Args.
|
/// Cuprate Args.
|
||||||
#[derive(clap::Parser, Debug)]
|
#[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.
|
/// 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 {
|
pub fn apply_args(&self, mut config: Config) -> Config {
|
||||||
if let Some(config_folder) = self.generate_config.as_ref() {
|
if let Some(config_folder) = self.generate_config.as_ref() {
|
||||||
// This will create the config file and exit.
|
println!("{EXAMPLE_CONFIG}");
|
||||||
create_default_config_file(config_folder)
|
exit(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
config.network = self.network;
|
config.network = self.network;
|
||||||
|
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -23,6 +23,7 @@ pub const EXAMPLE_CONFIG: &str = include_str!("../Cuprated.toml");
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::config::Config;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn version() {
|
fn version() {
|
||||||
|
@ -37,4 +38,9 @@ mod test {
|
||||||
assert_eq!(VERSION_BUILD, "0.0.1-release");
|
assert_eq!(VERSION_BUILD, "0.0.1-release");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn generate_config_text_is_valid() {
|
||||||
|
let config: Config = toml::from_str(EXAMPLE_CONFIG).unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue