mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Add self-validation framework for config
This commit is contained in:
@@ -18,6 +18,10 @@ pub struct CliArgs {
|
||||
/// User data root
|
||||
#[arg(long, default_value_t = {"../data/robocraft".to_string()})]
|
||||
pub data_robocraft: String,
|
||||
|
||||
/// Verify configuration and then exit
|
||||
#[arg(long)]
|
||||
pub validate: bool,
|
||||
}
|
||||
|
||||
impl CliArgs {
|
||||
|
||||
@@ -18,6 +18,18 @@ async fn index() -> impl Responder {
|
||||
async fn main() -> std::io::Result<()> {
|
||||
env_logger::init();
|
||||
let cli_args = cli::CliArgs::get();
|
||||
|
||||
if cli_args.validate {
|
||||
let conf = oj_rc_core::ConfigImpl::load(cli_args.assets_robocraft)?;
|
||||
let res = if conf.self_validate(&cli_args.data_robocraft) {
|
||||
log::info!("Config validated successfully (exit success)");
|
||||
Ok(())
|
||||
} else {
|
||||
Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "Config failed validation (exit failure)"))
|
||||
};
|
||||
return res;
|
||||
}
|
||||
|
||||
let cli_args2 = actix_web::web::Data::new(cli_args.clone());
|
||||
let rc_preloaded = actix_web::web::Data::new(cli_args.clone().preloaded().await);
|
||||
let internal_auth = actix_web::web::Data::new(crate::robocraft::intercom::IntercomAuth::new(&cli_args.data_robocraft)?);
|
||||
|
||||
Reference in New Issue
Block a user