From 9cac54b06ba2a7634f3a74294727cf32dc53e297 Mon Sep 17 00:00:00 2001 From: Freddie Ridell Date: Sat, 7 Mar 2026 00:33:59 +0000 Subject: [PATCH] Make bough-cli depend on bough-core and implement Config trait --- Cargo.lock | 1 + crates/bough-cli/Cargo.toml | 1 + crates/bough-cli/src/config.rs | 44 ++++++++++++++++++++++++++++++-- crates/bough-cli/src/main.rs | 11 ++------ crates/bough-core/src/lib.rs | 2 ++ crates/bough-core/src/session.rs | 13 +++++++--- 6 files changed, 58 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2ad4ae23..94ec6f09 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -73,6 +73,7 @@ dependencies = [ name = "bough-cli" version = "0.0.0" dependencies = [ + "bough-core", "facet", "facet-toml", "facet-yaml", diff --git a/crates/bough-cli/Cargo.toml b/crates/bough-cli/Cargo.toml index 0e519378..b7c2d03f 100644 --- a/crates/bough-cli/Cargo.toml +++ b/crates/bough-cli/Cargo.toml @@ -5,6 +5,7 @@ edition.workspace = true license.workspace = true [dependencies] +bough-core = { path = "../bough-core" } facet = "0.44" facet-toml = "0.44" facet-yaml = "0.44" diff --git a/crates/bough-cli/src/config.rs b/crates/bough-cli/src/config.rs index 641cf930..dcc53be8 100644 --- a/crates/bough-cli/src/config.rs +++ b/crates/bough-cli/src/config.rs @@ -38,8 +38,8 @@ pub struct Config { #[facet(default = 4)] pub workers: u64, - #[facet(default = "default")] - pub id: String, + pub include: Vec, + pub exclude: Vec, } struct TomlFormat; @@ -130,3 +130,43 @@ pub fn parse() -> Cli { output.print_warnings(); output.get_silent() } + +impl bough_core::Config for Config { + fn get_workers_count(&self) -> u64 { + self.workers + } + + fn get_bough_state_dir(&self) -> std::path::PathBuf { + todo!() + } + + fn get_base_root_path(&self) -> std::path::PathBuf { + todo!() + } + + fn get_base_include_globs(&self) -> impl Iterator { + vec![].into_iter() + } + + fn get_base_exclude_globs(&self) -> impl Iterator { + vec![].into_iter() + } + + fn get_langs(&self) -> impl Iterator { + vec![].into_iter() + } + + fn get_lang_include_globs( + &self, + language_id: bough_core::LanguageId, + ) -> impl Iterator { + vec![].into_iter() + } + + fn get_lang_exclude_globs( + &self, + language_id: bough_core::LanguageId, + ) -> impl Iterator { + vec![].into_iter() + } +} diff --git a/crates/bough-cli/src/main.rs b/crates/bough-cli/src/main.rs index ec2739bb..5e8cd016 100644 --- a/crates/bough-cli/src/main.rs +++ b/crates/bough-cli/src/main.rs @@ -13,9 +13,7 @@ fn main() { 3 => Level::DEBUG, _ => Level::TRACE, }; - tracing_subscriber::fmt() - .with_max_level(log_level) - .init(); + tracing_subscriber::fmt().with_max_level(log_level).init(); let config_path = resolve_config_path(); @@ -32,17 +30,12 @@ fn main() { println!("config file: {path}"); } println!("workers: {}", cli.config.workers); - println!("id: {}", cli.config.id); } ShowCommand::File => match config_path { Some(ref path) => println!("{path}"), None => println!("no config file found"), }, }, - Command::Run => { - println!("run: not yet implemented"); - println!("workers: {}", cli.config.workers); - println!("id: {}", cli.config.id); - } + Command::Run => {} } } diff --git a/crates/bough-core/src/lib.rs b/crates/bough-core/src/lib.rs index 3f6e5159..a7cc68b1 100644 --- a/crates/bough-core/src/lib.rs +++ b/crates/bough-core/src/lib.rs @@ -33,3 +33,5 @@ pub enum LanguageId { #[facet(rename = "ts")] Typescript, } + +pub use session::Config; diff --git a/crates/bough-core/src/session.rs b/crates/bough-core/src/session.rs index 5931b239..33e542cd 100644 --- a/crates/bough-core/src/session.rs +++ b/crates/bough-core/src/session.rs @@ -12,7 +12,7 @@ use crate::{ workspace::{Workspace, WorkspaceId}, }; -trait Config { +pub trait Config { fn get_workers_count(&self) -> u64; fn get_bough_state_dir(&self) -> PathBuf; @@ -359,7 +359,10 @@ mod tests { let dirs = workspace_dirs(dir.path()); assert_eq!(dirs.len(), 3, "expected 3 workspaces, got: {dirs:?}"); for d in &dirs { - assert!(d.join("src/a.js").exists(), "workspace should contain source files"); + assert!( + d.join("src/a.js").exists(), + "workspace should contain source files" + ); } } @@ -379,7 +382,11 @@ mod tests { config2.workers_count = 2; let _session2 = Session::new(config2).unwrap(); let dirs_after = workspace_dirs(dir.path()); - assert_eq!(dirs_after.len(), 2, "should reuse existing workspaces, not create new ones"); + assert_eq!( + dirs_after.len(), + 2, + "should reuse existing workspaces, not create new ones" + ); assert_eq!(dirs_before, dirs_after, "workspace dirs should be the same"); } -- knotmirror 0.0.1