2024-04-07 11:52:47 +01:00
|
|
|
use std::path::PathBuf;
|
2024-04-06 18:42:34 +01:00
|
|
|
|
2024-04-06 18:53:18 +01:00
|
|
|
use tracing::info;
|
|
|
|
|
2024-04-07 11:52:47 +01:00
|
|
|
use crate::filesystem::FileSystem;
|
|
|
|
|
|
|
|
pub(crate) fn init(fs: FileSystem) {
|
2024-04-06 18:42:34 +01:00
|
|
|
let file_name = "git-next-server.toml";
|
2024-04-07 11:52:47 +01:00
|
|
|
let path = PathBuf::from(file_name);
|
|
|
|
if fs.file_exists(&path) {
|
2024-04-07 08:56:33 +01:00
|
|
|
eprintln!(
|
|
|
|
"The configuration file already exists at {} - not overwritting it.",
|
|
|
|
file_name
|
|
|
|
);
|
|
|
|
} else {
|
2024-04-07 11:52:47 +01:00
|
|
|
match fs.write_file(file_name, include_str!("../server-default.toml")) {
|
|
|
|
Ok(_) => println!("Created a default configuration file at {}", file_name),
|
2024-04-06 18:42:34 +01:00
|
|
|
Err(e) => {
|
2024-04-07 11:52:47 +01:00
|
|
|
eprintln!("Failed to write to the configuration file: {}", e)
|
2024-04-06 18:42:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-04-06 18:53:18 +01:00
|
|
|
|
2024-04-07 11:52:47 +01:00
|
|
|
pub(crate) fn start(_fs: FileSystem) {
|
2024-04-06 18:53:18 +01:00
|
|
|
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(())
|
|
|
|
}
|