use clap::Subcommand; use std::path::Path; #[derive(Subcommand)] pub enum ArchiveCommand { Decompress { #[arg(short, long)] file: String, #[arg(short, long)] output: String, }, List { #[arg(short, long)] file: String, }, } pub fn handle_archive_command(cmd: ArchiveCommand) -> anyhow::Result<()> { match cmd { ArchiveCommand::Decompress { file, output } => { use crate::archive::{ArchiveConfig, ProcessorRegistry}; println!("Decompressing {} to {}", file, output); let archive_path = Path::new(&file); if !archive_path.exists() { return Err(anyhow::anyhow!("Archive file not found: {}", file)); } let config = ArchiveConfig::default(); let mut registry = ProcessorRegistry::new(config); registry.initialize()?; let output_path = Path::new(&output); std::fs::create_dir_all(output_path)?; let processor = registry.get_processor_mut(archive_path)?; let result = processor.extract_all(output_path)?; println!("✓ Archive decompressed to: {}", output); println!("✓ Files extracted: {}", result.success_files); println!("✓ Total size: {} bytes", result.total_bytes); } ArchiveCommand::List { file } => { use crate::archive::{ArchiveConfig, ProcessorRegistry}; println!("Listing contents of {}", file); let archive_path = Path::new(&file); if !archive_path.exists() { return Err(anyhow::anyhow!("Archive file not found: {}", file)); } let config = ArchiveConfig::default(); let mut registry = ProcessorRegistry::new(config); registry.initialize()?; let processor = registry.get_processor_mut(archive_path)?; let metadata = processor.open(archive_path)?; let entries = processor.list_entries()?; println!("=== Archive Contents ==="); println!("Format: {}", metadata.format); println!("Total files: {}", metadata.total_files); println!("Total size: {} bytes", metadata.total_size); println!(""); for entry in entries { println!(" {} ({} bytes)", entry.path.display(), entry.size); } } } Ok(()) }