use crate::platform::Platform;
use crate::server::Server;
use crate::{init_logging, JUPITER_REVISION, JUPITER_VERSION};
use std::sync::Arc;
#[derive(Default)]
pub struct Builder {
setup_logging: bool,
enable_signals: bool,
core_commands: bool,
setup_config: bool,
setup_commands: bool,
setup_server: bool,
version_info: String,
revision_info: String,
}
impl Builder {
pub fn new() -> Self {
Builder {
setup_logging: false,
enable_signals: false,
core_commands: false,
setup_config: false,
setup_commands: false,
setup_server: false,
version_info: "-".to_string(),
revision_info: "-".to_string(),
}
}
pub fn enable_all(mut self) -> Self {
self.setup_logging = true;
self.enable_signals = true;
self.core_commands = true;
self.setup_config = true;
self.setup_commands = true;
self.setup_server = true;
self
}
pub fn enable_logging(mut self) -> Self {
self.setup_logging = true;
self
}
pub fn disable_logging(mut self) -> Self {
self.setup_logging = false;
self
}
pub fn enable_signals(mut self) -> Self {
self.enable_signals = true;
self
}
pub fn disable_signals(mut self) -> Self {
self.enable_signals = false;
self
}
pub fn enable_core_commands(mut self) -> Self {
self.core_commands = true;
self
}
pub fn disable_core_commands(mut self) -> Self {
self.core_commands = false;
self
}
pub fn enable_config(mut self) -> Self {
self.setup_config = true;
self
}
pub fn disable_config(mut self) -> Self {
self.setup_config = false;
self
}
pub fn enable_commands(mut self) -> Self {
self.setup_commands = true;
self
}
pub fn disable_commands(mut self) -> Self {
self.setup_commands = false;
self
}
pub fn enable_server(mut self) -> Self {
self.setup_server = true;
self
}
pub fn disable_server(mut self) -> Self {
self.setup_server = false;
self
}
pub fn with_version(mut self, version: impl AsRef<str>, revision: impl AsRef<str>) -> Self {
self.version_info = version.as_ref().to_string();
self.revision_info = revision.as_ref().to_string();
self
}
pub async fn build(self) -> Arc<Platform> {
let platform = Platform::new();
if self.setup_logging {
init_logging();
}
log::info!(
"||. JUPITER (v {} - rev {}) running on {} core(s) in {} CPU(s)",
JUPITER_VERSION,
JUPITER_REVISION,
num_cpus::get(),
num_cpus::get_physical()
);
if self.enable_signals {
crate::signals::install(platform.clone());
}
if self.setup_config {
let _ = crate::config::install(platform.clone(), true).await;
}
if self.setup_server {
let _ = Server::install(&platform);
}
if self.setup_commands {
let _ = crate::commands::CommandDictionary::install(&platform);
if self.core_commands {
crate::core::install(platform.clone(), self.version_info, self.revision_info);
}
}
platform
}
}