Skip to content

Commit e7eb381

Browse files
🧹 Extract shared home_dir to fix duplication
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>
1 parent 43c970d commit e7eb381

8 files changed

Lines changed: 14 additions & 36 deletions

File tree

‎cli/src/commands/clean.rs‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub fn execute(all: bool) -> ExitCode {
2626

2727
if all {
2828
println!("Cleaning global package caches...");
29-
if let Some(home) = home_dir() {
29+
if let Some(home) = crate::dirs::home_dir() {
3030
let cache_dir = home.join(".techscript").join("cache");
3131
if cache_dir.exists() {
3232
if std::fs::remove_dir_all(&cache_dir).is_ok() {
@@ -49,8 +49,3 @@ pub fn execute(all: bool) -> ExitCode {
4949
ExitCode::IoError
5050
}
5151
}
52-
53-
fn home_dir() -> Option<std::path::PathBuf> {
54-
#[allow(deprecated)]
55-
std::env::home_dir()
56-
}

‎cli/src/commands/config.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::path::PathBuf;
99
pub fn execute(subcommand_str: Option<&str>) -> ExitCode {
1010
let sub = subcommand_str.unwrap_or("show").to_lowercase();
1111

12-
let home = match dirs::home_dir() {
12+
let home = match crate::dirs::home_dir() {
1313
Some(h) => h,
1414
None => {
1515
eprintln!("Error: Home directory not found.");

‎cli/src/commands/doctor.rs‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl DoctorContext {
9696
}
9797

9898
fn check_cache_dirs(&mut self) {
99-
if let Some(home) = dirs::home_dir() {
99+
if let Some(home) = crate::dirs::home_dir() {
100100
let config_dir = home.join(".techscript");
101101
let cache_dir = config_dir.join("cache");
102102
let packages_dir = config_dir.join("packages");
@@ -222,7 +222,7 @@ impl DoctorContext {
222222
if self.fix && !self.overall_success {
223223
println!("Performing automatic repair routines...");
224224
// Auto-initialize directories
225-
if let Some(home) = dirs::home_dir() {
225+
if let Some(home) = crate::dirs::home_dir() {
226226
let config_dir = home.join(".techscript");
227227
std::fs::create_dir_all(config_dir.join("cache")).ok();
228228
std::fs::create_dir_all(config_dir.join("packages")).ok();
@@ -300,11 +300,3 @@ pub fn execute(fix: bool) -> ExitCode {
300300
ExitCode::CompilationError
301301
}
302302
}
303-
304-
mod dirs {
305-
use std::path::PathBuf;
306-
pub fn home_dir() -> Option<PathBuf> {
307-
#[allow(deprecated)]
308-
std::env::home_dir()
309-
}
310-
}

‎cli/src/commands/repl.rs‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn execute() -> ExitCode {
3939
};
4040

4141
// Load persistent history
42-
let history_path = dirs::home_dir().map(|h| h.join(".techscript").join("repl_history"));
42+
let history_path = crate::dirs::home_dir().map(|h| h.join(".techscript").join("repl_history"));
4343
if let Some(ref path) = history_path {
4444
std::fs::create_dir_all(path.parent().unwrap()).ok();
4545
rl.load_history(path).ok();
@@ -271,11 +271,3 @@ fn dump_repl_bytecode(expr: &str) {
271271
}
272272
}
273273
}
274-
275-
mod dirs {
276-
use std::path::PathBuf;
277-
pub fn home_dir() -> Option<PathBuf> {
278-
#[allow(deprecated)]
279-
std::env::home_dir()
280-
}
281-
}

‎cli/src/config.rs‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl ConfigManager {
9797
let mut base = EffectiveConfig::default();
9898

9999
// 2. Global user config (~/.techscript/config.toml)
100-
if let Some(home) = dirs::home_dir() {
100+
if let Some(home) = crate::dirs::home_dir() {
101101
let global_path = home.join(".techscript").join("config.toml");
102102
if let Ok(content) = std::fs::read_to_string(global_path) {
103103
if let Ok(toml_cfg) = toml::from_str::<TomlConfig>(&content) {
@@ -257,11 +257,3 @@ fn apply_cli(base: &mut EffectiveConfig, cli: &CliConfig) {
257257
base.parallel_jobs = jobs;
258258
}
259259
}
260-
261-
mod dirs {
262-
use std::path::PathBuf;
263-
pub fn home_dir() -> Option<PathBuf> {
264-
#[allow(deprecated)]
265-
std::env::home_dir()
266-
}
267-
}

‎cli/src/dirs.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use std::path::PathBuf;
2+
3+
pub fn home_dir() -> Option<PathBuf> {
4+
#[allow(deprecated)]
5+
std::env::home_dir()
6+
}

‎cli/src/lib.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub mod compile_db;
1111
pub mod config;
1212
pub mod crash;
1313
pub mod diagnostics;
14+
pub mod dirs;
1415
pub mod events;
1516
pub mod exit_code;
1617
pub mod logging;

‎cli/src/main.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ fn main() {
202202
}
203203

204204
fn perform_first_run_check() {
205-
if let Some(home) = dirs::home_dir() {
205+
if let Some(home) = techscript_cli::dirs::home_dir() {
206206
let config_dir = home.join(".techscript");
207207
let config_file = config_dir.join("config.toml");
208208

0 commit comments

Comments
 (0)