From 23297e6f5c110776c744177801819c7bf3f9e53d Mon Sep 17 00:00:00 2001 From: Juliette Cordor Date: Wed, 27 Nov 2024 16:50:50 +1100 Subject: [PATCH] added config validations --- src/main.rs | 6 +++++- src/validations.rs | 5 +++++ src/validations/config.rs | 10 ++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/validations.rs create mode 100644 src/validations/config.rs diff --git a/src/main.rs b/src/main.rs index fcfb79d9..22cb3efd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,6 +15,7 @@ mod limits; mod logging; mod models; mod output; +mod validations; mod wrappers; use std::{ @@ -26,10 +27,11 @@ use clap::Parser; use commands::Commands; use logging::Logger; -use sprinkles::contexts::{AnyContext, User}; +use sprinkles::contexts::{AnyContext, ScoopContext, User}; #[cfg(feature = "contexts")] use sprinkles::contexts::Global; +use validations::Validate; shadow_rs::shadow!(shadow); @@ -171,6 +173,8 @@ async fn main() -> anyhow::Result<()> { COLOR_ENABLED.store(false, Ordering::Relaxed); } + ctx.config().validate()?; + debug!("Running command: {:?}", args.command); args.command.run(&ctx).await?; diff --git a/src/validations.rs b/src/validations.rs new file mode 100644 index 00000000..07d3c7dc --- /dev/null +++ b/src/validations.rs @@ -0,0 +1,5 @@ +pub mod config; + +pub trait Validate { + fn validate(&self) -> anyhow::Result<()>; +} diff --git a/src/validations/config.rs b/src/validations/config.rs new file mode 100644 index 00000000..e8c934be --- /dev/null +++ b/src/validations/config.rs @@ -0,0 +1,10 @@ +impl super::Validate for sprinkles::config::Scoop { + fn validate(&self) -> anyhow::Result<()> { + if self.no_junction { + anyhow::bail!("Junction links (symlinks) are required for sfsu to function currently. Please disable `no_junction` in your Scoop + config"); + } + + Ok(()) + } +}