diff --git a/src/cli/orchestrator.rs b/src/cli/orchestrator.rs index adb5b8e..a1bef3e 100644 --- a/src/cli/orchestrator.rs +++ b/src/cli/orchestrator.rs @@ -1,11 +1,11 @@ -use colored::*; -use futures::future::join_all; use crate::cli::Args; -use crate::settings::Config; -use crate::files::{execute_move, FileBatch, is_text_file, read_file_sample}; +use crate::files::{FileBatch, execute_move, is_text_file, read_file_sample}; use crate::gemini::GeminiClient; use crate::models::OrganizationPlan; +use crate::settings::Config; use crate::storage::{Cache, UndoLog}; +use colored::*; +use futures::future::join_all; use std::path::PathBuf; use std::sync::Arc; @@ -137,35 +137,38 @@ pub async fn handle_organization( ); let client_arc: Arc = Arc::new(client); - let semaphore: Arc = Arc::new(tokio::sync::Semaphore::new(args.max_concurrent)); + let semaphore: Arc = + Arc::new(tokio::sync::Semaphore::new(args.max_concurrent)); let tasks: Vec<_> = plan .files .iter_mut() .zip(batch.paths.iter()) - .map(|(file_category, path): (&mut crate::models::FileCategory, &PathBuf)| { - let client: Arc = Arc::clone(&client_arc); - let filename: String = file_category.filename.clone(); - let category: String = file_category.category.clone(); - let path: PathBuf = path.clone(); - let semaphore: Arc = Arc::clone(&semaphore); + .map( + |(file_category, path): (&mut crate::models::FileCategory, &PathBuf)| { + let client: Arc = Arc::clone(&client_arc); + let filename: String = file_category.filename.clone(); + let category: String = file_category.category.clone(); + let path: PathBuf = path.clone(); + let semaphore: Arc = Arc::clone(&semaphore); - async move { - if is_text_file(&path) { - let _permit = semaphore.acquire().await.unwrap(); - if let Some(content) = read_file_sample(&path, 5000) { - println!("Reading content of {}...", filename.green()); - client - .get_ai_sub_category(&filename, &category, &content) - .await + async move { + if is_text_file(&path) { + let _permit = semaphore.acquire().await.unwrap(); + if let Some(content) = read_file_sample(&path, 5000) { + println!("Reading content of {}...", filename.green()); + client + .get_ai_sub_category(&filename, &category, &content) + .await + } else { + String::new() + } } else { String::new() } - } else { - String::new() } - } - }) + }, + ) .collect(); let sub_categories: Vec = join_all(tasks).await; diff --git a/src/files/mover.rs b/src/files/mover.rs index d72a28f..627d0dc 100644 --- a/src/files/mover.rs +++ b/src/files/mover.rs @@ -1,14 +1,10 @@ -use colored::*; use crate::models::OrganizationPlan; use crate::storage::UndoLog; +use colored::*; use std::io; use std::{ffi::OsStr, fs, path::Path}; -pub fn execute_move( - base_path: &Path, - plan: OrganizationPlan, - mut undo_log: Option<&mut UndoLog>, -) { +pub fn execute_move(base_path: &Path, plan: OrganizationPlan, mut undo_log: Option<&mut UndoLog>) { println!("\n{}", "--- EXECUTION PLAN ---".bold().underline()); if plan.files.is_empty() { diff --git a/src/files/undo.rs b/src/files/undo.rs index fc2523f..4373556 100644 --- a/src/files/undo.rs +++ b/src/files/undo.rs @@ -1,5 +1,5 @@ -use colored::*; use crate::storage::UndoLog; +use colored::*; use std::fs; use std::io; use std::path::Path; diff --git a/src/gemini/client.rs b/src/gemini/client.rs index 242008d..494786c 100644 --- a/src/gemini/client.rs +++ b/src/gemini/client.rs @@ -1,8 +1,8 @@ -use crate::models::OrganizationPlan; -use crate::storage::Cache; use crate::gemini::errors::GeminiError; use crate::gemini::prompt::PromptBuilder; use crate::gemini::types::{GeminiResponse, OrganizationPlanResponse}; +use crate::models::OrganizationPlan; +use crate::storage::Cache; use reqwest::Client; use serde_json::json; use std::path::Path; diff --git a/src/gemini/mod.rs b/src/gemini/mod.rs index 27166a5..650bdea 100644 --- a/src/gemini/mod.rs +++ b/src/gemini/mod.rs @@ -5,4 +5,6 @@ pub mod types; pub use client::GeminiClient; pub use errors::GeminiError; -pub use types::{Candidate, Content, FileCategoryResponse, GeminiResponse, OrganizationPlanResponse, Part}; +pub use types::{ + Candidate, Content, FileCategoryResponse, GeminiResponse, OrganizationPlanResponse, Part, +}; diff --git a/src/gemini/prompt.rs b/src/gemini/prompt.rs index 4211da8..f33db59 100644 --- a/src/gemini/prompt.rs +++ b/src/gemini/prompt.rs @@ -1,5 +1,5 @@ -use crate::models::{FileCategory, OrganizationPlan}; use crate::gemini::types::OrganizationPlanResponse; +use crate::models::{FileCategory, OrganizationPlan}; impl OrganizationPlanResponse { pub fn to_organization_plan(self) -> OrganizationPlan { diff --git a/src/lib.rs b/src/lib.rs index 5c2a45f..e3ca460 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,14 +1,14 @@ pub mod cli; -pub mod settings; pub mod files; pub mod gemini; pub mod models; +pub mod settings; pub mod storage; pub use cli::Args; -pub use settings::Config; pub use files::{FileBatch, execute_move, is_text_file, read_file_sample, undo_moves}; pub use gemini::GeminiClient; pub use gemini::GeminiError; pub use models::{FileCategory, FileMoveRecord, MoveStatus, OrganizationPlan}; +pub use settings::Config; pub use storage::{Cache, UndoLog}; diff --git a/src/main.rs b/src/main.rs index bf74a91..54d6da9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,9 @@ -use noentropy::cli::{Args, orchestrator::{handle_organization, handle_undo}}; -use noentropy::settings::{get_or_prompt_api_key, get_or_prompt_download_folder}; use clap::Parser; +use noentropy::cli::{ + Args, + orchestrator::{handle_organization, handle_undo}, +}; +use noentropy::settings::{get_or_prompt_api_key, get_or_prompt_download_folder}; #[tokio::main] async fn main() -> Result<(), Box> { diff --git a/src/models/mod.rs b/src/models/mod.rs index 3d69ea3..5e9e68b 100644 --- a/src/models/mod.rs +++ b/src/models/mod.rs @@ -1,7 +1,7 @@ -pub mod organization; pub mod metadata; pub mod move_record; +pub mod organization; -pub use organization::{FileCategory, OrganizationPlan}; pub use metadata::{CacheEntry, FileMetadata}; pub use move_record::{FileMoveRecord, MoveStatus}; +pub use organization::{FileCategory, OrganizationPlan}; diff --git a/src/settings/config.rs b/src/settings/config.rs index 8d5a5f0..7d4771b 100644 --- a/src/settings/config.rs +++ b/src/settings/config.rs @@ -136,4 +136,3 @@ impl Default for Config { } } } - diff --git a/src/settings/tests.rs b/src/settings/tests.rs index 82838b7..5399b6d 100644 --- a/src/settings/tests.rs +++ b/src/settings/tests.rs @@ -40,9 +40,7 @@ fn test_validate_api_key_invalid() { #[test] fn test_validate_folder_path_valid() { let temp_dir = tempfile::tempdir().unwrap(); - assert!(Prompter::validate_folder_path( - temp_dir.path() - )); + assert!(Prompter::validate_folder_path(temp_dir.path())); } #[test] @@ -52,9 +50,7 @@ fn test_validate_folder_path_invalid() { ))); let temp_file = tempfile::NamedTempFile::new().unwrap(); - assert!(!Prompter::validate_folder_path( - temp_file.path() - )); + assert!(!Prompter::validate_folder_path(temp_file.path())); } #[test] diff --git a/src/storage/cache.rs b/src/storage/cache.rs index 6d36f4b..ed80424 100644 --- a/src/storage/cache.rs +++ b/src/storage/cache.rs @@ -199,4 +199,3 @@ impl Cache { } } } - diff --git a/src/storage/mod.rs b/src/storage/mod.rs index d25efb0..3e9d278 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -6,8 +6,8 @@ pub use undo_log::UndoLog; #[cfg(test)] mod tests { - use crate::storage::{Cache, UndoLog}; use crate::models::{FileMoveRecord, MoveStatus}; + use crate::storage::{Cache, UndoLog}; use std::path::PathBuf; #[test] @@ -42,9 +42,9 @@ mod tests { let mut log = UndoLog::new(); let source = PathBuf::from("/from/file.txt"); let dest = PathBuf::from("/to/file.txt"); - + log.record_move(source.clone(), dest.clone()); - + assert!(log.has_completed_moves()); assert_eq!(log.get_completed_count(), 1); } @@ -54,9 +54,9 @@ mod tests { let mut log = UndoLog::new(); let source = PathBuf::from("/from/file.txt"); let dest = PathBuf::from("/to/file.txt"); - + log.record_failed_move(source.clone(), dest.clone()); - + assert!(!log.has_completed_moves()); assert_eq!(log.get_completed_count(), 0); } @@ -66,10 +66,10 @@ mod tests { let mut log = UndoLog::new(); let source = PathBuf::from("/from/file.txt"); let dest = PathBuf::from("/to/file.txt"); - + log.record_move(source.clone(), dest.clone()); assert_eq!(log.get_completed_count(), 1); - + log.mark_as_undone(&dest); assert_eq!(log.get_completed_count(), 0); } @@ -79,7 +79,7 @@ mod tests { let record = FileMoveRecord::new( PathBuf::from("/from"), PathBuf::from("/to"), - MoveStatus::Completed + MoveStatus::Completed, ); assert_eq!(record.status, MoveStatus::Completed); } @@ -97,4 +97,4 @@ mod tests { let usage = log.get_directory_usage(PathBuf::from("/").as_path()); assert!(usage.is_empty()); } -} \ No newline at end of file +} diff --git a/src/storage/undo_log.rs b/src/storage/undo_log.rs index 6480857..dc28641 100644 --- a/src/storage/undo_log.rs +++ b/src/storage/undo_log.rs @@ -179,4 +179,3 @@ impl UndoLog { usage } } -