50 lines
1.5 KiB
Rust
50 lines
1.5 KiB
Rust
use std::io::Write;
|
|
|
|
use tracing::info;
|
|
|
|
pub(crate) fn init() {
|
|
let file_name = "git-next-server.toml";
|
|
let path = std::path::Path::new(file_name);
|
|
if !path.exists() {
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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(())
|
|
}
|