diff --git a/Cargo.toml b/Cargo.toml index dc2c630..8e3fde9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,19 +7,22 @@ edition = "2021" #bytes = "1.9" clap = { version = "4.5", features = ["cargo", "derive"] } color-eyre = "0.6" -#derive_more = { version = "1.0", features = [ -# "as_ref", -# "constructor", +derive_more = { version = "1.0", features = [ + "as_ref", + "constructor", # "deref", # "display", -# "from", -#] } + # "from", + #] } + #serde = { version = "1.0", features = ["derive"] } + "from", +] } # kxio = {path = "../kxio/"} kxio = "3.2" -#serde = { version = "1.0", features = ["derive"] } +serde = { version = "1.0", features = ["derive"] } #serde_json = "1.0" tokio = { version = "1.41", features = ["full"] } -#toml = "0.8" +toml = "0.8" #tracing= "0.1" #tracing-subscriber = "0.3" diff --git a/justfile b/justfile index 976199e..c715dc2 100644 --- a/justfile +++ b/justfile @@ -5,6 +5,7 @@ build: cargo fmt cargo fmt --check cargo clippy + cargo machete # cargo build cargo tarpaulin --skip-clean --out Html # cargo test diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..235abbd --- /dev/null +++ b/src/config.rs @@ -0,0 +1,24 @@ +// +use color_eyre::Result; + +use crate::{f, s, Ctx, NAME}; + +#[derive( + Clone, + Debug, + derive_more::From, + PartialEq, + Eq, + PartialOrd, + Ord, + derive_more::AsRef, + serde::Deserialize, +)] +pub struct AppConfig {} +impl AppConfig { + pub fn load(ctx: &Ctx) -> Result { + let file = ctx.fs.base().join(f!("{NAME}.toml")); + let str = ctx.fs.file(&file).reader()?; + Ok(toml::from_str(s!(str).as_str())?) + } +} diff --git a/src/lib.rs b/src/lib.rs index b06130f..386c314 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,7 @@ use std::path::PathBuf; use clap::Parser; use kxio::{fs::FileSystem, net::Net}; +mod config; mod init; mod macros; mod template; @@ -45,6 +46,7 @@ pub async fn run(ctx: Ctx) -> color_eyre::Result<()> { color_eyre::install()?; let commands = Commands::parse(); + let _cfg = config::AppConfig::load(&ctx)?; match commands.command { Command::Init => init::run(&ctx)?, Command::Check => todo!("check"), diff --git a/src/tests/mod.rs b/src/tests/mod.rs index f1a8183..156165c 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -4,6 +4,27 @@ use assert2::let_assert; +use crate::{config::AppConfig, f, NAME}; + +mod config { + use super::*; + + #[test] + fn load_config() { + //given + let fs = given::a_filesystem(); + let file = fs.base().join(f!("{}.toml", NAME)); + fs.file(&file).write("").expect("write file"); + let ctx = given::a_context(fs.as_real(), given::a_network().into()); + + //when + let_assert!(Ok(config) = AppConfig::load(&ctx)); + + //then + assert_eq!(config, AppConfig {}); + } +} + mod init { use test_log::test;