1use clap::{Parser, Subcommand};
4use std::path::PathBuf;
5use anyhow::Result;
6
7use znippy_compress::compress_dir;
8use znippy_decompress::decompress_archive;
9use znippy_common::{verify_archive_integrity, list_archive_contents, VerifyReport};
10
11#[derive(Parser)]
12#[command(name = "znippy")]
13#[command(about = "Znippy: fast archive format with per-file compression", long_about = None)]
14struct Cli {
15 #[command(subcommand)]
16 command: Commands,
17}
18
19#[derive(Subcommand)]
20enum Commands {
21 Compress {
23 #[arg(short, long)]
24 input: PathBuf,
25
26 #[arg(short, long)]
27 output: PathBuf,
28
29 #[arg(long)]
30 no_skip: bool,
31 },
32
33 Decompress {
35 #[arg(short, long)]
36 input: PathBuf,
37
38 #[arg(short, long)]
39 output: PathBuf,
40 },
41
42 List {
44 #[arg(short, long)]
45 input: PathBuf,
46 },
47
48 Verify {
50 #[arg(short, long)]
51 input: PathBuf,
52 },
53}
54
55pub fn run() -> Result<()> {
56 env_logger::init();
57 let cli = Cli::parse();
58
59 match cli.command {
60 Commands::Compress { input, output, no_skip } => {
61 let report = compress_dir(&input, &output,no_skip)?;
62 println!("\nβ
Komprimering klar:");
63 println!("π Totalt antal filer: {}", report.total_files);
64 println!("π Totalt antal chunks: {}", report.chunks);
65
66 println!("π Totalt antal kataloger: {}", report.total_dirs);
67 println!("π¦ Filer komprimerade: {}", report.compressed_files);
68 println!("π Filer ej komprimerade: {}", report.uncompressed_files);
69 println!("π₯ Totalt inlΓ€sta bytes: {}", report.total_bytes_in);
70 println!("π€ Totalt skrivna bytes: {}", report.total_bytes_out);
71 println!("π Bytes som komprimerades: {}", report.compressed_bytes);
72 println!("π Bytes ej komprimerade: {}", report.uncompressed_bytes);
73 println!("π Komprimeringsgrad: {:.2}%", report.compression_ratio);
74 }
75
76 Commands::Decompress { input, output } => {
77 let report: VerifyReport = decompress_archive(&input, &output)?;
78 println!("\nβ
Dekomprimering och verifiering klar:");
79 println!("π Totala filer: {}", report.total_files);
80 println!("π Verifierade filer: {}", report.verified_files);
81 println!("π₯ chunks: {}", report.chunks);
82 println!("β Korrupta filer: {}", report.corrupt_files);
83 println!("π₯ Totala bytes: {}", report.total_bytes);
84 println!("π€ Verifierade bytes: {}", report.verified_bytes);
85 println!("β οΈ Korrupta bytes: {}", report.corrupt_bytes);
86
87 }
88
89 Commands::List { input } => {
90 list_archive_contents(&input)?;
91 }
92
93 Commands::Verify { input } => {
94 let report: VerifyReport = verify_archive_integrity(&input)?;
95 println!("\nπ Verifiering klar:");
96 println!("π Totala filer: {}", report.total_files);
97 println!("π Verifierade filer: {}", report.verified_files);
98 println!("β Korrupta filer: {}", report.corrupt_files);
99 println!("π₯ Totala bytes: {}", report.total_bytes);
100 println!("π€ Verifierade bytes: {}", report.verified_bytes);
101 println!("β οΈ Korrupta bytes: {}", report.corrupt_bytes);
102 }
103 }
104
105 Ok(())
106}