1use anyhow::Result;
4use clap::{Parser, Subcommand};
5use std::path::PathBuf;
6
7use znippy_common::{VerifyReport, list_archive_contents, verify_archive_integrity};
8use znippy_compress::compress_dir;
9use znippy_decompress::decompress_archive;
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 {
61 input,
62 output,
63 no_skip,
64 } => {
65 let report = compress_dir(&input, &output, no_skip)?;
66 println!("\nβ
Komprimering klar:");
67 println!("π Totalt antal filer: {}", report.total_files);
68 println!("π Totalt antal chunks: {}", report.chunks);
69
70 println!("π Totalt antal kataloger: {}", report.total_dirs);
71 println!("π¦ Filer komprimerade: {}", report.compressed_files);
72 println!(
73 "π Filer ej komprimerade: {}",
74 report.uncompressed_files
75 );
76 println!("π₯ Totalt inlΓ€sta bytes: {}", report.total_bytes_in);
77 println!("π€ Totalt skrivna bytes: {}", report.total_bytes_out);
78 println!("π Bytes som komprimerades: {}", report.compressed_bytes);
79 println!(
80 "π Bytes ej komprimerade: {}",
81 report.uncompressed_bytes
82 );
83 println!(
84 "π Komprimeringsgrad: {:.2}%",
85 report.compression_ratio
86 );
87 }
88
89 Commands::Decompress { input, output } => {
90 let report: VerifyReport = decompress_archive(&input, &output)?;
91 println!("\nβ
Dekomprimering och verifiering klar:");
92 println!("π Totala filer: {}", report.total_files);
93 println!("π Verifierade filer: {}", report.verified_files);
94 println!("π₯ chunks: {}", report.chunks);
95 println!("β Korrupta filer: {}", report.corrupt_files);
96 println!("π₯ Totala bytes: {}", report.total_bytes);
97 println!("π€ Verifierade bytes: {}", report.verified_bytes);
98 println!("β οΈ Korrupta bytes: {}", report.corrupt_bytes);
99 }
100
101 Commands::List { input } => {
102 list_archive_contents(&input)?;
103 }
104
105 Commands::Verify { input } => {
106 let report: VerifyReport = verify_archive_integrity(&input)?;
107 println!("\nπ Verifiering klar:");
108 println!("π Totala filer: {}", report.total_files);
109 println!("π Verifierade filer: {}", report.verified_files);
110 println!("β Korrupta filer: {}", report.corrupt_files);
111 println!("π₯ Totala bytes: {}", report.total_bytes);
112 println!("π€ Verifierade bytes: {}", report.verified_bytes);
113 println!("β οΈ Korrupta bytes: {}", report.corrupt_bytes);
114 }
115 }
116
117 Ok(())
118}