2024-02-14 19:35:19 +01:00
|
|
|
use crate::args_parser::Command;
|
|
|
|
use crate::editor::commands::editor::editor;
|
|
|
|
use crate::editor::try_reload_server::reload;
|
2024-02-14 19:48:08 +01:00
|
|
|
use clap::Parser;
|
|
|
|
use editor::commands::fetch::fetch;
|
|
|
|
use editor::commands::query::query;
|
|
|
|
use tracing_subscriber::util::SubscriberInitExt;
|
2024-02-14 20:55:28 +01:00
|
|
|
use crate::editor::commands::init::init;
|
2024-02-14 19:35:19 +01:00
|
|
|
|
2024-02-14 19:48:08 +01:00
|
|
|
mod args_parser;
|
2024-02-14 19:35:19 +01:00
|
|
|
#[cfg(feature = "editor")]
|
|
|
|
mod editor;
|
2024-02-14 19:48:08 +01:00
|
|
|
mod schema;
|
2024-02-14 19:35:19 +01:00
|
|
|
#[cfg(feature = "server")]
|
|
|
|
mod server;
|
|
|
|
|
|
|
|
#[cfg(all(not(feature = "editor"), not(feature = "server")))]
|
|
|
|
compile_error!("Please enable either the \"editor\" or the \"server\" feature");
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let args = args_parser::MainCommand::parse();
|
|
|
|
tracing_subscriber::FmtSubscriber::builder()
|
|
|
|
.with_max_level(args.log_level())
|
2024-02-14 19:48:08 +01:00
|
|
|
.finish()
|
|
|
|
.init();
|
|
|
|
let args_parser::MainCommand {
|
|
|
|
data_paths,
|
|
|
|
run_mode,
|
|
|
|
..
|
|
|
|
} = args;
|
2024-02-14 19:35:19 +01:00
|
|
|
match run_mode {
|
|
|
|
Command::Serve(params) => {
|
|
|
|
#[cfg(not(feature = "server"))]
|
|
|
|
{
|
|
|
|
panic!("Server mode has not been compiled into this executable. Please rebuild with the \"server\" feature enabled.")
|
|
|
|
}
|
|
|
|
#[cfg(feature = "server")]
|
|
|
|
server::init(data_paths, params);
|
|
|
|
}
|
2024-02-14 19:48:08 +01:00
|
|
|
Command::Fetch {
|
|
|
|
save,
|
|
|
|
handles,
|
|
|
|
handles_are_files,
|
|
|
|
new_domain,
|
|
|
|
server_reload,
|
|
|
|
} => {
|
|
|
|
fetch(
|
|
|
|
data_paths.database_path,
|
|
|
|
save,
|
|
|
|
handles.into_iter(),
|
|
|
|
handles_are_files,
|
|
|
|
new_domain,
|
|
|
|
);
|
2024-02-14 19:35:19 +01:00
|
|
|
reload(data_paths.pid_file_path, server_reload);
|
|
|
|
}
|
2024-02-14 19:48:08 +01:00
|
|
|
Command::Query { resource } => query(data_paths.database_path, resource),
|
|
|
|
Command::Editor {
|
|
|
|
save,
|
|
|
|
resource,
|
|
|
|
server_reload,
|
|
|
|
} => {
|
2024-02-14 19:35:19 +01:00
|
|
|
editor(data_paths.database_path, save, resource);
|
|
|
|
|
|
|
|
reload(data_paths.pid_file_path, server_reload);
|
|
|
|
}
|
2024-02-14 20:55:28 +01:00
|
|
|
Command::Init { force } => {
|
|
|
|
init(data_paths.database_path, force);
|
|
|
|
}
|
2024-02-14 19:35:19 +01:00
|
|
|
}
|
|
|
|
}
|