fixed formatting

This commit is contained in:
2025-12-30 02:10:00 +05:30
parent 33784d8f1d
commit 2211057e4f
14 changed files with 55 additions and 58 deletions

View File

@@ -1,11 +1,11 @@
use colored::*;
use futures::future::join_all;
use crate::cli::Args; use crate::cli::Args;
use crate::settings::Config; use crate::files::{FileBatch, execute_move, is_text_file, read_file_sample};
use crate::files::{execute_move, FileBatch, is_text_file, read_file_sample};
use crate::gemini::GeminiClient; use crate::gemini::GeminiClient;
use crate::models::OrganizationPlan; use crate::models::OrganizationPlan;
use crate::settings::Config;
use crate::storage::{Cache, UndoLog}; use crate::storage::{Cache, UndoLog};
use colored::*;
use futures::future::join_all;
use std::path::PathBuf; use std::path::PathBuf;
use std::sync::Arc; use std::sync::Arc;
@@ -137,35 +137,38 @@ pub async fn handle_organization(
); );
let client_arc: Arc<GeminiClient> = Arc::new(client); let client_arc: Arc<GeminiClient> = Arc::new(client);
let semaphore: Arc<tokio::sync::Semaphore> = Arc::new(tokio::sync::Semaphore::new(args.max_concurrent)); let semaphore: Arc<tokio::sync::Semaphore> =
Arc::new(tokio::sync::Semaphore::new(args.max_concurrent));
let tasks: Vec<_> = plan let tasks: Vec<_> = plan
.files .files
.iter_mut() .iter_mut()
.zip(batch.paths.iter()) .zip(batch.paths.iter())
.map(|(file_category, path): (&mut crate::models::FileCategory, &PathBuf)| { .map(
let client: Arc<GeminiClient> = Arc::clone(&client_arc); |(file_category, path): (&mut crate::models::FileCategory, &PathBuf)| {
let filename: String = file_category.filename.clone(); let client: Arc<GeminiClient> = Arc::clone(&client_arc);
let category: String = file_category.category.clone(); let filename: String = file_category.filename.clone();
let path: PathBuf = path.clone(); let category: String = file_category.category.clone();
let semaphore: Arc<tokio::sync::Semaphore> = Arc::clone(&semaphore); let path: PathBuf = path.clone();
let semaphore: Arc<tokio::sync::Semaphore> = Arc::clone(&semaphore);
async move { async move {
if is_text_file(&path) { if is_text_file(&path) {
let _permit = semaphore.acquire().await.unwrap(); let _permit = semaphore.acquire().await.unwrap();
if let Some(content) = read_file_sample(&path, 5000) { if let Some(content) = read_file_sample(&path, 5000) {
println!("Reading content of {}...", filename.green()); println!("Reading content of {}...", filename.green());
client client
.get_ai_sub_category(&filename, &category, &content) .get_ai_sub_category(&filename, &category, &content)
.await .await
} else {
String::new()
}
} else { } else {
String::new() String::new()
} }
} else {
String::new()
} }
} },
}) )
.collect(); .collect();
let sub_categories: Vec<String> = join_all(tasks).await; let sub_categories: Vec<String> = join_all(tasks).await;

View File

@@ -1,14 +1,10 @@
use colored::*;
use crate::models::OrganizationPlan; use crate::models::OrganizationPlan;
use crate::storage::UndoLog; use crate::storage::UndoLog;
use colored::*;
use std::io; use std::io;
use std::{ffi::OsStr, fs, path::Path}; use std::{ffi::OsStr, fs, path::Path};
pub fn execute_move( pub fn execute_move(base_path: &Path, plan: OrganizationPlan, mut undo_log: Option<&mut UndoLog>) {
base_path: &Path,
plan: OrganizationPlan,
mut undo_log: Option<&mut UndoLog>,
) {
println!("\n{}", "--- EXECUTION PLAN ---".bold().underline()); println!("\n{}", "--- EXECUTION PLAN ---".bold().underline());
if plan.files.is_empty() { if plan.files.is_empty() {

View File

@@ -1,5 +1,5 @@
use colored::*;
use crate::storage::UndoLog; use crate::storage::UndoLog;
use colored::*;
use std::fs; use std::fs;
use std::io; use std::io;
use std::path::Path; use std::path::Path;

View File

@@ -1,8 +1,8 @@
use crate::models::OrganizationPlan;
use crate::storage::Cache;
use crate::gemini::errors::GeminiError; use crate::gemini::errors::GeminiError;
use crate::gemini::prompt::PromptBuilder; use crate::gemini::prompt::PromptBuilder;
use crate::gemini::types::{GeminiResponse, OrganizationPlanResponse}; use crate::gemini::types::{GeminiResponse, OrganizationPlanResponse};
use crate::models::OrganizationPlan;
use crate::storage::Cache;
use reqwest::Client; use reqwest::Client;
use serde_json::json; use serde_json::json;
use std::path::Path; use std::path::Path;

View File

@@ -5,4 +5,6 @@ pub mod types;
pub use client::GeminiClient; pub use client::GeminiClient;
pub use errors::GeminiError; pub use errors::GeminiError;
pub use types::{Candidate, Content, FileCategoryResponse, GeminiResponse, OrganizationPlanResponse, Part}; pub use types::{
Candidate, Content, FileCategoryResponse, GeminiResponse, OrganizationPlanResponse, Part,
};

View File

@@ -1,5 +1,5 @@
use crate::models::{FileCategory, OrganizationPlan};
use crate::gemini::types::OrganizationPlanResponse; use crate::gemini::types::OrganizationPlanResponse;
use crate::models::{FileCategory, OrganizationPlan};
impl OrganizationPlanResponse { impl OrganizationPlanResponse {
pub fn to_organization_plan(self) -> OrganizationPlan { pub fn to_organization_plan(self) -> OrganizationPlan {

View File

@@ -1,14 +1,14 @@
pub mod cli; pub mod cli;
pub mod settings;
pub mod files; pub mod files;
pub mod gemini; pub mod gemini;
pub mod models; pub mod models;
pub mod settings;
pub mod storage; pub mod storage;
pub use cli::Args; pub use cli::Args;
pub use settings::Config;
pub use files::{FileBatch, execute_move, is_text_file, read_file_sample, undo_moves}; pub use files::{FileBatch, execute_move, is_text_file, read_file_sample, undo_moves};
pub use gemini::GeminiClient; pub use gemini::GeminiClient;
pub use gemini::GeminiError; pub use gemini::GeminiError;
pub use models::{FileCategory, FileMoveRecord, MoveStatus, OrganizationPlan}; pub use models::{FileCategory, FileMoveRecord, MoveStatus, OrganizationPlan};
pub use settings::Config;
pub use storage::{Cache, UndoLog}; pub use storage::{Cache, UndoLog};

View File

@@ -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 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] #[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> { async fn main() -> Result<(), Box<dyn std::error::Error>> {

View File

@@ -1,7 +1,7 @@
pub mod organization;
pub mod metadata; pub mod metadata;
pub mod move_record; pub mod move_record;
pub mod organization;
pub use organization::{FileCategory, OrganizationPlan};
pub use metadata::{CacheEntry, FileMetadata}; pub use metadata::{CacheEntry, FileMetadata};
pub use move_record::{FileMoveRecord, MoveStatus}; pub use move_record::{FileMoveRecord, MoveStatus};
pub use organization::{FileCategory, OrganizationPlan};

View File

@@ -136,4 +136,3 @@ impl Default for Config {
} }
} }
} }

View File

@@ -40,9 +40,7 @@ fn test_validate_api_key_invalid() {
#[test] #[test]
fn test_validate_folder_path_valid() { fn test_validate_folder_path_valid() {
let temp_dir = tempfile::tempdir().unwrap(); let temp_dir = tempfile::tempdir().unwrap();
assert!(Prompter::validate_folder_path( assert!(Prompter::validate_folder_path(temp_dir.path()));
temp_dir.path()
));
} }
#[test] #[test]
@@ -52,9 +50,7 @@ fn test_validate_folder_path_invalid() {
))); )));
let temp_file = tempfile::NamedTempFile::new().unwrap(); let temp_file = tempfile::NamedTempFile::new().unwrap();
assert!(!Prompter::validate_folder_path( assert!(!Prompter::validate_folder_path(temp_file.path()));
temp_file.path()
));
} }
#[test] #[test]

View File

@@ -199,4 +199,3 @@ impl Cache {
} }
} }
} }

View File

@@ -6,8 +6,8 @@ pub use undo_log::UndoLog;
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::storage::{Cache, UndoLog};
use crate::models::{FileMoveRecord, MoveStatus}; use crate::models::{FileMoveRecord, MoveStatus};
use crate::storage::{Cache, UndoLog};
use std::path::PathBuf; use std::path::PathBuf;
#[test] #[test]
@@ -79,7 +79,7 @@ mod tests {
let record = FileMoveRecord::new( let record = FileMoveRecord::new(
PathBuf::from("/from"), PathBuf::from("/from"),
PathBuf::from("/to"), PathBuf::from("/to"),
MoveStatus::Completed MoveStatus::Completed,
); );
assert_eq!(record.status, MoveStatus::Completed); assert_eq!(record.status, MoveStatus::Completed);
} }

View File

@@ -179,4 +179,3 @@ impl UndoLog {
usage usage
} }
} }