2024-04-06 18:42:34 +01:00
|
|
|
use std::io::Write;
|
|
|
|
|
2024-04-06 18:53:18 +01:00
|
|
|
use tracing::info;
|
|
|
|
|
2024-04-06 18:42:34 +01:00
|
|
|
pub(crate) fn init() {
|
|
|
|
let file_name = "git-next-server.toml";
|
|
|
|
let path = std::path::Path::new(file_name);
|
2024-04-07 08:56:33 +01:00
|
|
|
if path.exists() {
|
|
|
|
eprintln!(
|
|
|
|
"The configuration file already exists at {} - not overwritting it.",
|
|
|
|
file_name
|
|
|
|
);
|
|
|
|
} else {
|
2024-04-06 18:42:34 +01:00
|
|
|
match std::fs::File::create(file_name) {
|
|
|
|
Ok(mut file) => {
|
|
|
|
println!("Created a default configuration file at {}", file_name);
|
|
|
|
match file.write_all(include_bytes!("../server-default.toml")) {
|
|
|
|
Ok(_) => println!("Wrote to the configuration file successfully."),
|
|
|
|
Err(e) => {
|
|
|
|
eprintln!("Failed to write to the configuration file: {}", e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(e) => {
|
|
|
|
eprintln!("Failed to create a default configuration file: {}", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-04-06 18:53:18 +01:00
|
|
|
|
|
|
|
pub(crate) fn start() {
|
|
|
|
let Ok(_) = init_logging() else {
|
|
|
|
eprintln!("Failed to initialize logging.");
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
info!("Starting Server...");
|
|
|
|
// todo!()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn init_logging() -> Result<(), tracing::subscriber::SetGlobalDefaultError> {
|
|
|
|
use tracing_subscriber::prelude::*;
|
|
|
|
|
|
|
|
let console_layer = console_subscriber::ConsoleLayer::builder().spawn();
|
|
|
|
|
|
|
|
let subscriber = tracing_subscriber::fmt::layer()
|
|
|
|
// NOTE: set RUSTLOG in ${root}/.cargo/config
|
|
|
|
.with_target(false)
|
|
|
|
.with_file(true)
|
|
|
|
.with_line_number(true);
|
|
|
|
tracing_subscriber::registry()
|
|
|
|
.with(console_layer)
|
|
|
|
.with(subscriber)
|
|
|
|
.init();
|
|
|
|
Ok(())
|
|
|
|
}
|