From e7eb381cd229e1bd87fde40b05a4e47fea691c80 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 22 Sep 2026 07:43:58 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20Extract=20shared=20home=5Fdir=20?= =?UTF-8?q?to=20fix=20duplication?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaces duplicated implementations of `mod dirs { ... }` in `clean.rs`, `doctor.rs`, `repl.rs`, and `config.rs` with a centralized utility in `cli/src/dirs.rs`. Updates call sites to reference `crate::dirs::home_dir()`. Co-authored-by: Tcode-Motion <188012755+Tcode-Motion@users.noreply.github.com> --- cli/src/commands/clean.rs | 7 +------ cli/src/commands/config.rs | 2 +- cli/src/commands/doctor.rs | 12 ++---------- cli/src/commands/repl.rs | 10 +--------- cli/src/config.rs | 10 +--------- cli/src/dirs.rs | 6 ++++++ cli/src/lib.rs | 1 + cli/src/main.rs | 2 +- 8 files changed, 14 insertions(+), 36 deletions(-) create mode 100644 cli/src/dirs.rs diff --git a/cli/src/commands/clean.rs b/cli/src/commands/clean.rs index 0ee9de97..12d4ffdd 100644 --- a/cli/src/commands/clean.rs +++ b/cli/src/commands/clean.rs @@ -26,7 +26,7 @@ pub fn execute(all: bool) -> ExitCode { if all { println!("Cleaning global package caches..."); - if let Some(home) = home_dir() { + if let Some(home) = crate::dirs::home_dir() { let cache_dir = home.join(".techscript").join("cache"); if cache_dir.exists() { if std::fs::remove_dir_all(&cache_dir).is_ok() { @@ -49,8 +49,3 @@ pub fn execute(all: bool) -> ExitCode { ExitCode::IoError } } - -fn home_dir() -> Option { - #[allow(deprecated)] - std::env::home_dir() -} diff --git a/cli/src/commands/config.rs b/cli/src/commands/config.rs index 3e749e8b..4d89df26 100644 --- a/cli/src/commands/config.rs +++ b/cli/src/commands/config.rs @@ -9,7 +9,7 @@ use std::path::PathBuf; pub fn execute(subcommand_str: Option<&str>) -> ExitCode { let sub = subcommand_str.unwrap_or("show").to_lowercase(); - let home = match dirs::home_dir() { + let home = match crate::dirs::home_dir() { Some(h) => h, None => { eprintln!("Error: Home directory not found."); diff --git a/cli/src/commands/doctor.rs b/cli/src/commands/doctor.rs index 243aa876..7dcf783c 100644 --- a/cli/src/commands/doctor.rs +++ b/cli/src/commands/doctor.rs @@ -96,7 +96,7 @@ impl DoctorContext { } fn check_cache_dirs(&mut self) { - if let Some(home) = dirs::home_dir() { + if let Some(home) = crate::dirs::home_dir() { let config_dir = home.join(".techscript"); let cache_dir = config_dir.join("cache"); let packages_dir = config_dir.join("packages"); @@ -222,7 +222,7 @@ impl DoctorContext { if self.fix && !self.overall_success { println!("Performing automatic repair routines..."); // Auto-initialize directories - if let Some(home) = dirs::home_dir() { + if let Some(home) = crate::dirs::home_dir() { let config_dir = home.join(".techscript"); std::fs::create_dir_all(config_dir.join("cache")).ok(); std::fs::create_dir_all(config_dir.join("packages")).ok(); @@ -300,11 +300,3 @@ pub fn execute(fix: bool) -> ExitCode { ExitCode::CompilationError } } - -mod dirs { - use std::path::PathBuf; - pub fn home_dir() -> Option { - #[allow(deprecated)] - std::env::home_dir() - } -} diff --git a/cli/src/commands/repl.rs b/cli/src/commands/repl.rs index 35108267..7b6e885f 100644 --- a/cli/src/commands/repl.rs +++ b/cli/src/commands/repl.rs @@ -39,7 +39,7 @@ pub fn execute() -> ExitCode { }; // Load persistent history - let history_path = dirs::home_dir().map(|h| h.join(".techscript").join("repl_history")); + let history_path = crate::dirs::home_dir().map(|h| h.join(".techscript").join("repl_history")); if let Some(ref path) = history_path { std::fs::create_dir_all(path.parent().unwrap()).ok(); rl.load_history(path).ok(); @@ -271,11 +271,3 @@ fn dump_repl_bytecode(expr: &str) { } } } - -mod dirs { - use std::path::PathBuf; - pub fn home_dir() -> Option { - #[allow(deprecated)] - std::env::home_dir() - } -} diff --git a/cli/src/config.rs b/cli/src/config.rs index 3c6de852..5279bba3 100644 --- a/cli/src/config.rs +++ b/cli/src/config.rs @@ -97,7 +97,7 @@ impl ConfigManager { let mut base = EffectiveConfig::default(); // 2. Global user config (~/.techscript/config.toml) - if let Some(home) = dirs::home_dir() { + if let Some(home) = crate::dirs::home_dir() { let global_path = home.join(".techscript").join("config.toml"); if let Ok(content) = std::fs::read_to_string(global_path) { if let Ok(toml_cfg) = toml::from_str::(&content) { @@ -257,11 +257,3 @@ fn apply_cli(base: &mut EffectiveConfig, cli: &CliConfig) { base.parallel_jobs = jobs; } } - -mod dirs { - use std::path::PathBuf; - pub fn home_dir() -> Option { - #[allow(deprecated)] - std::env::home_dir() - } -} diff --git a/cli/src/dirs.rs b/cli/src/dirs.rs new file mode 100644 index 00000000..ac06ef26 --- /dev/null +++ b/cli/src/dirs.rs @@ -0,0 +1,6 @@ +use std::path::PathBuf; + +pub fn home_dir() -> Option { + #[allow(deprecated)] + std::env::home_dir() +} diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 30379215..6185b81d 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -11,6 +11,7 @@ pub mod compile_db; pub mod config; pub mod crash; pub mod diagnostics; +pub mod dirs; pub mod events; pub mod exit_code; pub mod logging; diff --git a/cli/src/main.rs b/cli/src/main.rs index 8110ad3f..d410fe96 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -202,7 +202,7 @@ fn main() { } fn perform_first_run_check() { - if let Some(home) = dirs::home_dir() { + if let Some(home) = techscript_cli::dirs::home_dir() { let config_dir = home.join(".techscript"); let config_file = config_dir.join("config.toml");